Skip to content

Commit 8a35fb7

Browse files
committed
优化文件合并功能。
1 parent cadf03a commit 8a35fb7

1 file changed

Lines changed: 2 additions & 27 deletions

File tree

src/main/java/com/xwintop/xJavaFxTool/services/littleTools/FileMergeToolService.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void mergeAction() throws Exception { //合并操作
7676
} else if (fileTypeSelectIndex == 1) {
7777
mergeCsv(fileList, newFilePath);
7878
} else if (fileTypeSelectIndex == 2) {
79-
mergeFile();
79+
mergeFile(fileList, newFilePath);
8080
}
8181
}
8282

@@ -159,32 +159,7 @@ public void mergeCsv(List<File> fileList, String newFilePath) throws Exception {
159159
printer.close();
160160
}
161161

162-
public void mergeFile() throws Exception {
163-
String filePath = fileMergeToolController.getSelectFileTextField().getText();
164-
String[] filePaths = filePath.split("\\|");
165-
List<File> fileList = new ArrayList<>();
166-
for (String path : filePaths) {
167-
File file = new File(path);
168-
if (file.isDirectory()) {
169-
fileList.addAll(Arrays.asList(file.listFiles()));
170-
} else {
171-
fileList.add(file);
172-
}
173-
}
174-
String newFilePath = null;
175-
if (fileList.get(0).isDirectory()) {
176-
if (StringUtils.isNotEmpty(fileMergeToolController.getSaveFilePathTextField().getText())) {
177-
newFilePath = StringUtils.appendIfMissing(fileMergeToolController.getSaveFilePathTextField().getText(), "/", "/", "\\") + "merge_file";
178-
} else {
179-
newFilePath = fileList.get(0).getPath() + "/merge_file.txt";
180-
}
181-
} else {
182-
if (StringUtils.isNotEmpty(fileMergeToolController.getSaveFilePathTextField().getText())) {
183-
newFilePath = StringUtils.appendIfMissing(fileMergeToolController.getSaveFilePathTextField().getText(), "/", "/", "\\") + "merge_" + fileList.get(0).getName();
184-
} else {
185-
newFilePath = fileList.get(0).getParent() + "/merge_" + fileList.get(0).getName();
186-
}
187-
}
162+
public void mergeFile(List<File> fileList, String newFilePath) throws Exception {
188163
File resultFile = new File(newFilePath);
189164
try {
190165
FileChannel resultFileChannel = new FileOutputStream(resultFile, true).getChannel();

0 commit comments

Comments
 (0)