import java.io.*;
public class chk
{
String className;
String command,command1,command2;
public String getMsg(String fileName,String Path)
{
String dir;
command1="cd "+Path;
dir=Path.charAt(0)+Path.charAt(1)+"";
command2=dir;
command = "javac " + fileName;
String a=executeCommand(command1);
a=executeCommand(command2);
String output = executeCommand(command);
if(output.compareTo("")==0)
output = "Compilation Successfull!!";
return output;
}
private String executeCommand(String command)
{
StringBuffer output = new StringBuffer();
Process p;
try
{
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader1 = new BufferedReader(new InputStreamReader(p.getErrorStream()));
BufferedReader reader2 = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader1.readLine())!= null)
{
output.append(line + "\n");
}
while ((line = reader2.readLine())!= null)
{
output.append(line + "\n");
}
} catch (Exception e)
{
e.printStackTrace();
}
return output.toString();
}
public static void main(String args[])throws IOException
{
String x;
chk ob=new chk();
x=ob.getMsg("MyClass.java","D:\test");
System.out.println("OUtput : "+x);
}
}
오류실행 명령
나중에 내가 다른 자바 파일을 컴파일 할 수 있도록 자바 파일의 도움으로 명령 프롬프트에서 명령의 무리를 실행하려고 내 컴퓨터의 다른 드라이브에있는 "MyClass.java"라는 이름이지만 다음과 같은 오류가 발생합니다. 즉, 첫 번째 명령 인 "command1 ="cd "+ Path; 이 줄. pls 도움!
제 3의 매개 변수 대신에 무엇을 줄 것입니까? – rick
파일에 파일을 전송하는 방법, 즉 "D : \ test"경로가 있습니까? – rick
'새 파일 ("D : \\ 테스트")'. 이것은'File' 클래스의 문서에 있습니다. – ajb