【发布时间】:2014-11-08 08:14:32
【问题描述】:
我正在尝试使用通过命令行运行配置给出的原始路径写入文件。但是,我很难将这些部分组合在一起。我试图通过 Report 类构造函数传递文件名,然后使用它使用打印方法写入文件。我究竟做错了什么?对不起,我的java很差……
public static void main(String[] args) throws IOException {
String roadFilename = args[0];
String cellNetworkFilename = args[1];
String imageFilename = args[2];
String reportFilename = args[3];
Report report = new Report(
new java.io.File(reportFilename)
);
report.add(message);
report.write();
cellNetwork.hasCoverage(roadNetwork);
}
public class Report {
String mess;
java.util.ArrayList<String> something = new java.util.ArrayList<String>();
File file;
private PrintWriter print;
public Report(File file) {
this.file=file;
// TODO Auto-generated constructor stub
}
public void add(String message) {
something.add(message);
public void write() {
try {
print = new PrintWriter(
new BufferedWriter(
new FileWriter(file)));
print.println(something);
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
System.exit(0);
}
【问题讨论】:
-
1) 为什么不关闭文件?,2) 为什么
e.printStackTrace();被注释掉了?
标签: java file-io printwriter