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

读文件
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();
}
上一篇:双色球生成方法


下一篇:JAVAj基础(字符流自定义字符数组的拷贝)