📄 save.java~16~
字号:
package test;
import java.io.File;
import java.io.PrintWriter;
import javax.swing.JList;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
public class Save {
String path;
JList subList;
JList fileList;
String[] others;
public Save(String path,JList subList,JList fileList,String[] others){
this.path = path;
this.subList = subList;
this.fileList = fileList;
this.others = others;
}
public void SaveFile(){//保存各配置内容到文件中
String[] subContent = new GetListContent(subList).getContent();//获得subList中的内容
String[] fileContent = new GetListContent(fileList).getContent();//获得fileList中的内容
int subContent_len = subContent.length;
int fileContent_len = fileContent.length;
File file = new File(path);
PrintWriter writer = null;//按行写入
try{
writer = new PrintWriter(new FileOutputStream(file));
writer.println("-l " + others[0]);//写入根目录层次
if(subContent_len > 0){
//分解字段,再写入文件
for(int i = 0; i < subContent_len; i++){
if(subContent[0].equals(null) ||subContent[0].equals(""))
break;
else{
writer.println("-d " + subContent[i]);
}
}
}//写入子文件
writer.println("-fm " + others[1]);//写入文件包含或排除
if(fileContent_len > 0){
for(int i = 0; i < fileContent_len; i++){
if(fileContent[0].equals(null)||fileContent[0].equals(""))
break;
else
writer.println("-f " + fileContent[i]);
}
}//写入文件
writer.println("-v " + others[2]);//写入文件配置结果
writer.println("-s " + others[3]); //写入结果排序方式
}
catch(FileNotFoundException e){
e.printStackTrace();
}
finally{
if(writer != null){
writer.close();//关闭输出文件流
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -