java写⼊本地⽂件两种⽅式
写⼊本地⽂件代码如下:
/**
* str:    要写⼊的⽂件内容  例如:{\"id\":1777944995971746430,\"frName\":\"会议纪要\",\"createDate\":\"2018-7-11\"} * path:      ⽂件具体路径        例如:D:/111/2018/7/11/会议纪要.json
*/
public static void writeLocalStrOne(String str,String path){
try {
File file = new File(path);
if (!ParentFile().exists()) {
}
mkdirs方法
if(str != null && !"".equals(str)){
FileWriter fw = new FileWriter(file, true);
fw.write(str);//写⼊本地⽂件中
fw.flush();
fw.close();
System.out.println("执⾏完毕!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* str:    要写⼊的⽂件内容  例如:{\"id\":1777944995971746430,\"frName\":\"会议纪要\",\"createDate\":\"2018-7-11\"} * path:      ⽂件具体路径        例如:D:/111/2018/7/11/会议纪要.json
*/
public static void writeLocalStrTwo(String str,String path){
try {
File file = new File(path);
if (!ParentFile().exists()) {
}
if(str != null && !"".equals(str)){
FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
osw.write(str);
osw.flush();
osw.close();
System.out.println("执⾏完毕!");
}
} catch (IOException e) {
e.printStackTrace();
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。