我正在用java处理一个文件,我正在计算该文件每一行中特定文件的出现次数我正在为每一行启动一个线程,如下所示
input = new BufferedReader(new FileReader(new File(finaName)));
String line = null;
while ((line = input.readLine()) != null) {
FileThread t = new FileThread(line);
t.start();
}
FileThread st = new FileThread();
System.out.println("Size"+st.list.size());
文件线程.java
public class FileThread extends Thread
List<String> list = new ArrayList<String>();
public FileThread(){}
public FileThread(String line){}
private String line = null;
public void run() {
String[] tokens = line.split("\\|", LIST.length);
String Symbol = null;
try {
Symbol = tokens[4];
list.add(symbol);
} catch (Throwable t1) {
t1.printStackTrace();
}
}
问题是我总是将 Size 设为 0 。请查看示例输出
BIM!A BIM!B BIM!C BIM!D 尺寸0