我是新来的。我有这样一个简单的项目:
public class test {
public test() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
String path = "test\template.txt"
FileOutputStream fileOut = new FileOutputStream(path);
}
}
我想改变我的字符串"路径"形式的蚂蚁任务。我可以这样做吗?
建议
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class Application {
public Application() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) throws FileNotFoundException {
if (args.length < 1) {
System.out.println("Usage " + Application.class.getSimpleName() + " template-file");
}
String pathStr = args[0];
File path = new File(pathStr);
if (path.exists()) {
System.err.println("Already a file exists at location '" + path + "'");
}
FileOutputStream fileOut = new FileOutputStream(path);
}
}