最近在写一个java的爬虫,将读取到的数据写入txt文件中,现在奉上源码
//单行写出
private static boolean writeTxtCount(String path,String content) {
BufferedWriter bufferedWriter = null;
try {
bufferedWriter = new BufferedWriter(new FileWriter(path,true));
//bufferedWriter.write(content+ “\r\n”);分行写
bufferedWriter.write(content);
return true;
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
调取时的方法:
writeTxtCount(“D:/”+user.name+".txt",写入的内容);