import java.io.*;public class Test
{
public static void main(String[] args)
{
try
{
// 这里如果去掉2> errors.txt编译成功,加了重定向 ">" 输出就有问题了
// 实际使用中我需要的就是一个导出文件的功能,这里使用了一个简单的例子
String command = "javac d:\\Test.java 2> errors.txt"; System.out.println(command);
Process child = Runtime.getRuntime().exec(command);
System.out.println(child.getErrorStream());
BufferedReader err =
new BufferedReader(
new InputStreamReader(child.getErrorStream()));
while ((currentLine = err.readLine()) != null)
System.out.println(currentLine);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}}
各位给点建议?
{
public static void main(String[] args)
{
try
{
// 这里如果去掉2> errors.txt编译成功,加了重定向 ">" 输出就有问题了
// 实际使用中我需要的就是一个导出文件的功能,这里使用了一个简单的例子
String command = "javac d:\\Test.java 2> errors.txt"; System.out.println(command);
Process child = Runtime.getRuntime().exec(command);
System.out.println(child.getErrorStream());
BufferedReader err =
new BufferedReader(
new InputStreamReader(child.getErrorStream()));
while ((currentLine = err.readLine()) != null)
System.out.println(currentLine);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}}
各位给点建议?
写这个的目的不是为了编译成功,而是生成这个txt文件。
exec参数不知道怎样设定,有没有大哥解决下这个问题
import java.io.*;public class Export
{
public static void main(String[] args)
{
try
{
// 这里如果去掉2> errors.txt编译成功,加了重定向 ">" 输出就有问题了
// 实际使用中我需要的就是一个导出文件的功能,这里使用了一个简单的例子
String command = "javac F:\\JAVA\\Test.java";
String currentLine="";
int lineNum=0;
//System.out.println("A");
System.out.println(command);
//System.out.println("B");
Process child = Runtime.getRuntime().exec(command);
System.out.println(child.getErrorStream());
//System.out.println("C");
BufferedReader err = new BufferedReader(new InputStreamReader(child.getErrorStream()));
PrintWriter out1=new PrintWriter(new BufferedWriter(new FileWriter("F:\\JAVA\\Test2.txt")));
out1.println(String.valueOf(lineNum));
while ((currentLine = err.readLine()) != null){
System.out.println(currentLine);
out1.println(String.valueOf(lineNum)+" "+currentLine);
lineNum++;
} out1.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}}
java -cp e:\\saxonb8\\saxon8.jar net.sf.saxon.Transform d:\\query1.xml d:\\query1.xsl > d:\\result.html
使用这样的命令
I/O这块用的比较少,呵呵,我自己再看看,应该差不多了,多谢