1.在指定路径下生成文件夹
String filePath1 = "H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\_test2";
File file1=new File(filePath1);
if(!file1.exists()){
file1.mkdir();
}
String filePath = "H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\_test2\\module";
File file=new File(filePath);
if(!file.exists()){
file.mkdir();
}
2.在指定路径下生成文件、写入内容
try{
BufferedWriter bw = new BufferedWriter(new FileWriter("H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\_test2\\module\\bar.txt"));
bw.write("Hello bar!");
bw.close();
}catch(IOException e) {
e.printStackTrace();
}
3.把一个文件另存为
- 引依赖
import org.apache.commons.io.FileUtils;
FileUtils.copyFile(new File("H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\_test1\\module\\aa.vue"), new File("H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\仪表板20\\module\\aa_1.vue"));
FileUtils.copyFileToDirectory(new File("H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\_test1\\module\\aa.vue"), new File("H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\仪表板\\module"));