public class FileWriter_ {
public static void main(String[] args) {
String filePath = "e:\note.txt";
FileWriter fileWriter = null;
char[] chars = {'a','b','c'};
try {
fileWriter = new FileWriter(filePath);
//写入单个字符
fileWriter.write('H');
//写入字符数组
fileWriter.write(chars);
//写入指定数组的指定部分
fileWriter.write("天上星亮晶晶".toCharArray(),4,2);
//写入字符串
fileWriter.write(" 黄河之水天上来~");
//写入字符串的指定部分
fileWriter.write("滚滚长江东逝水",0,2);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
//一定要close或flush,否则会写不进去字符
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)