本文介绍了运行.exe和.bin(Linux)文件的JAVA程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨...我用Java创建了一个程序,该程序显示了Windows的详细信息,并且还运行了.exe文件,其路径已提供给它...
我的问题是,相同的代码在linux中会做同样的事情吗?我的意思是它将显示OS为linux并运行.bin文件...
帮助将不胜感激:-)
Hi... I have created a program in java that shows the windows detail and also runs .exe files whose path is provided to it...
My question is will the same code do the same in linux?? I mean would it show OS to be linux and would run .bin files...
Help would be appreciated :-)
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Project1
{
/**
* @param args
*/
public static void main(String[] args)
{
OSdetails();
execute();
}
public static void OSdetails()
{
String osName= System.getProperty("os.name");
System.out.println("Operating system name =>"+ osName);
String osVersion= System.getProperty("os.version");
System.out.println("Operating system version =>"+ osVersion);
String osArch= System.getProperty("os.arch");
System.out.println("Operating system name =>"+ osArch);
//JOptionPane.showMessageDialog(null, osName +"\n"+ "Version: " +osVersion+ "\n"+ "Architecture: "+ osArch);
}
public static void execute()
{
Runtime r = Runtime.getRuntime();
System.out.print("Please enter a path ");
Scanner Input = new Scanner(System.in);
String path = Input.nextLine();
//String path = JOptionPane.showInputDialog("Please enter a path");
Process p = null;
try
{
if(path != "")
p=r.exec(path);
//System.out.print(path);
}
catch(Exception e)
{
System.out.println("File Not found");
//execute();
}
}
}
推荐答案
这篇关于运行.exe和.bin(Linux)文件的JAVA程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!