简单的问题是我可以使用其他函数来代替 println,因为我想将非静态变量输出到文件 usig out.println();
这是我的代码:
import java.io.*;
public class main {
String outputString ="Math.sqrt(25);" ;
static String outputPath ="src/output.txt";
/**
* @param args
*/
public static void main(String[] args) throws IOException {
File f;
f= new File (outputPath);
//file creation
if(!f.exists()){
f.createNewFile();
System.out.println("File has been created");
}else{
f.delete();
System.out.println("1. File has been deleted");
f.createNewFile();
System.out.println("2. File has been created");
}
//adding string(text) to file
try{
FileWriter outFile = new FileWriter(args[0]);
PrintWriter out = new PrintWriter(outFile);
out.println(outputString);
out.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
如果那是不可能的,也许还有另一种方法可以绕过它。我的主要问题是我想在代码中创建一个字符串。但这似乎很难做到:)对此有任何帮助:)