首先我已经有了这个代码:
public class TextTest {
public static void main(String[] args) {
try {
List<Text> v = new ArrayList<Text>();
v.add(new Text(args[0]));
v.add(new Text(args[1]));
v.add(new Text(args[2]));
System.out.println(v);
Collections.sort(v);
System.out.println(v);
}
catch ( ArrayIndexOutOfBoundsException e) {
System.err.println("Enter three files for comparation");
}
}
我需要创建一个名为 Text
包含打开和读取txt文件的代码。但是,如何构建构造函数来接收包含3个txt文件的目录,同时创建并读取这些文件?文件将存储在此处:
v.add(new Text(args[0]));
v.add(new Text(args[1]));
v.add(new Text(args[2]));
1条答案
按热度按时间s71maibg1#
假设你有3个文本文件
text1.txt
,text2.txt
,和text3.txt
包括以下内容:文本1.txt:
文本2.txt:
文本3.txt:
你可以让
Text
实施Comparable<Text>
:用法示例: