java追加文件

package com.ibm.beans;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class TestWriteFile2 {
public static void writeFile(String filePathAndName,String fileContent){
File f = new File(filePathAndName);
try{
if(!f.exists()){
f.getParentFile().mkdirs();
f.createNewFile();
}
FileWriter fw = new FileWriter(f,true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(fileContent);
bw.newLine();
bw.flush();
bw.close();
System.out.println("写入成功!!!");
}catch(Exception e){
System.out.println("写文件出错!");
e.printStackTrace();
}
}
public static void main(String[] args){
String filePathAndName = "D:/hd.txt";
String fileContent = "\r\n你是左眼睛,我是右眼睛";
writeFile(filePathAndName,fileContent);
}
}

你可能感兴趣的:(java,IBM,F#)