//一般不能实例化一个Runtime对象,应用程序也不能创建自己的Runtime 类实例,但可以通过getRuntime 方法获取当前Runtime运行时对象的引用。一旦得到了一个当前的Runtime对象的引用,就可以调用Runtime对象的方法去控制Java虚拟机的状态和行为。
Runtime ce=Runtime.getRuntime();
File pFile = new File("四则运算记录");
pFile.mkdirs();
String filename = JTFUserName.getText()+".his";
File aUserRec = new File(pFile,filename);
if(aUserRec.exists())
{
    try{
        //ce.exec("cmd   /c   start  "+aUserRec.getAbsolutePath());
        //上面这样是不能打开的 因为没有东西能打开.his文件 会跳出来搜索应用商店
         ce.exec("notepad.exe "+aUserRec.getAbsolutePath());
    }catch(IOException exc){
         exc.printStackTrace();
    }
}
else
{
    JFrame nullFileWarning = new JFrame();
    JOptionPane.showMessageDialog(nullFileWarning,"该用户暂无记录!");
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐