out.writeChars(descs[i]); out.writeChar('\\n'); }
//关闭数据输出流
out.close(); //创建数据输入流
DataInputStream in = new DataInputStream( new FileInputStream(\
double price; int unit; String desc; double total = 0.0; try {
//利用数据输入流读文件内容
while (true) {
price = in.readDouble();
in.readChar(); // throws out the tab unit = in.readInt();
in.readChar(); // throws out the tab
26
desc = in.readLine();
System.out.println(\
unit + \ desc + \
total = total + unit * price; } }
//捕获异常
catch (EOFException e) {
e.printStackTrace();
}
System.out.println(\
//关闭数据输入流
in.close(); } }
9、创建两个线程,每个线程打印出线程名字后再睡眠,给其它线程以执行的机会,主线程也要打印出线程名字后再睡眠,每个线程前后共睡眠5次。要求分别采用从Thread中继承和实现Runnable接口两种方式来实现程序。(即写两个程序)
27
答案略
28