java如何写入txt文件

public class TxtWrite {

    public static void main(String args[]){
        contentToTxt("D:\\xyky.txt","3");
    }
    public static void contentToTxt(String filePath, String content) {
        try{
            BufferedWriter writer = new BufferedWriter(new FileWriter(new File(filePath),true));
            writer.write("\n"+content);
            writer.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
 
 



 

 

posted @ 2016-12-09 21:50  xxyBlogs  阅读(13788)  评论(0编辑  收藏  举报