java 比较两个txt文件,请看清楚内容,若回答的好,另外送50分!
1.txt01,02,03,04,05,0602,03,04,14,17,2202,03,04,14,17,3002,03,04,14,17,3103,06,10,15,...
1.txt
01,02,03,04,05,06
02,03,04,14,17,22
02,03,04,14,17,30
02,03,04,14,17,31
03,06,10,15,29,33
04,05,10,15,29,31
04,11,13,26,28,30
04,11,13,26,28,33
2.txt
01,02,03,04,05
02,03,04,14,17
03,05,10,15,29
04,11,13,26,28
05,11,13,26,28
希望高手大神帮帮忙,让比较完的结果显示如下:
3.txt:
将1.txt中一行数字内含有2.txt一行中5个数字的一行内容输出到3.txt:
如结果为:
01,02,03,04,05,06
02,03,04,14,17,22
02,03,04,14,17,30
02,03,04,14,17,31
04,11,13,26,28,30 展开
01,02,03,04,05,06
02,03,04,14,17,22
02,03,04,14,17,30
02,03,04,14,17,31
03,06,10,15,29,33
04,05,10,15,29,31
04,11,13,26,28,30
04,11,13,26,28,33
2.txt
01,02,03,04,05
02,03,04,14,17
03,05,10,15,29
04,11,13,26,28
05,11,13,26,28
希望高手大神帮帮忙,让比较完的结果显示如下:
3.txt:
将1.txt中一行数字内含有2.txt一行中5个数字的一行内容输出到3.txt:
如结果为:
01,02,03,04,05,06
02,03,04,14,17,22
02,03,04,14,17,30
02,03,04,14,17,31
04,11,13,26,28,30 展开
1个回答
展开全部
题目太长,50分太少,还答得好才给,增加分数并直接设置悬赏,就给你做。
更多追问追答
追问
我先给50分,你帮我写好了我再给你50分!
追答
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) throws IOException {
List<String> lines1 = Files.readAllLines(Paths.get("D:", "1.txt"));
List<List<String>> nums1 = lines1.stream().map(e -> Arrays.asList(e.split(","))).collect(Collectors.toList());
List<String> lines2 = Files.readAllLines(Paths.get("D:", "2.txt"));
List<List<String>> nums2 = lines1.stream().map(e -> Arrays.asList(e.split(","))).collect(Collectors.toList());
List<String> lines3 = new ArrayList<>();
for (int i = 0; i < lines1.size(); i++) {
for (int j = 0; j < lines2.size(); j++) {
if (nums1.get(i).containsAll(nums2.get(j))) {
lines3.add(lines1.get(i));
break;
}
}
}
Files.write(Paths.get("D:", "3.txt"), lines3);
}
}
其中路径的名字Paths.get("D:", "3.txt")中间可以有多个字符串,
比如Paths.get("D:","文件夹A","文件夹B", "3.txt")
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询