展开全部
以下代码仅供参考
PrintWriter out = new PrintWriter("D:\\1.txt");
for(Object o : list){
out.print(o);
out.print(",");
}
out.print(ss);
out.println();
out.close();
追答
PrintWriter out;
try {
out = new PrintWriter("D:\\1.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
out.print(ss);
out.println();
out.close();
加一个try-catch吧
展开全部
public static void writeFile(String content, String file) {
try {
File f = new File(file).getParentFile();
if (!f.exists()) {
f.mkdirs();
}
FileOutputStream fos = new FileOutputStream(file);
Writer out = new OutputStreamWriter(fos, "UTF-8");
out.flush();
out.write(content);
out.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
log.debug("Write File:" + file);
}
try {
File f = new File(file).getParentFile();
if (!f.exists()) {
f.mkdirs();
}
FileOutputStream fos = new FileOutputStream(file);
Writer out = new OutputStreamWriter(fos, "UTF-8");
out.flush();
out.write(content);
out.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
log.debug("Write File:" + file);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询