File data = new File("data.txt")
try {
InputStreamReader read = new InputStreamReader(new FileInputStream(
data), "UTF-8")
final BufferedReader bufferedReader = new BufferedReader(read)
for (int i = 0i <5i++) {
new Thread(new Runnable() {
@Override
public void run() {
String lineTXT = null
synchronized (bufferedReader) {
try {
while ((lineTXT = bufferedReader.readLine()) != null) {
System.out.println(Thread.currentThread()+":"+lineTXT)
bufferedReader.notify()
bufferedReader.wait()
}
} catch (IOException e) {
e.printStackTrace()
} catch (InterruptedException e) {
e.printStackTrace()
}finally{
bufferedReader.notifyAll()
}
}
}
}).start()
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace()
} catch (FileNotFoundException e) {
e.printStackTrace()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)