文件操作,读文件或者写文件

时间:2019-08-16 16:36:30   收藏:0   阅读:85
读文件
public static String[] readFilePram(String filename) throws IOException {
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
String line;
String[] args = null;
while ((line = br.readLine()) != null) {
args = line.split(",");
}
br.close();
fr.close();
return args;
}

写文件
publi static void writeFilePram(String dir, String filename, String content) throws IOException {
File file = new File(dir + filename);

FileOutputStream fw = null;
if (!file.exists()) {
file.createNewFile();
fw = new FileOutputStream(file);
} else {
fw = new FileOutputStream(file, true);
}
OutputStreamWriter bw = new OutputStreamWriter(fw, "UTF-8");

bw.write( content + "\r\n");

bw.close();
fw.close();
}

原文:https://www.cnblogs.com/meadow/p/11364498.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!