try{
//file data
String data = "hello word ! ";
//file path
String path="/home/test.sh";
File file =new File(path);
//if file doesnt exists, then create it
if(!file.exists()){
file.createNewFile();
}
//覆盖之前的内容
FileWriter fileWritter = new FileWriter(file.getPath());
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write(data);
bufferWritter.write("\n");
bufferWritter.close();
}catch(IOException e){
e.printStackTrace();
}
Java 生成文件(覆盖写)
最新推荐文章于 2024-07-01 14:19:13 发布