2个回答
展开全部
class Worker implements Runnable {
private String filename;
public Worker(String filename) {
this.filename = filename;
}
@Override
public void run() {
FileReader fr = new FileReader(filename);
fr.read(); // 读一个字符
... // 以及其他操作
fr.close();
}
}
public class Foobar {
public static void main(String[] args) {
Worker w1 = new Worker("a.txt");
Worker w2 = new Worker("b.txt");
Worker w3 = new Worker("c.txt")
Thread t1 = new Thread(w1);
Thread t2 = new Thread(w2);
Thread t3 = new Thread(w3);
t1.start();
t2.start();
t3.start();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询