问答题

下面程序的功能是从键盘读取一行文本并将该文本存储到文件中。当用户运行该程序时,需要输入一行文本并按下回车键。然后在DOS系统提示符处输入type file.txt并按下Enter键,这时屏幕会显示type file.txt的内容。通过这个命令可以验证该程序的功能。请在每条横线处填写一条语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件代码清单如下:
import java.io.*;
public class DoFile
public static void main(String args[])

byte buffername[]=______[80];
try

System.out.println("\nEnter a line to be saved to disk:");
int bytesbleck= ______;
FileOutputStream f=new FileOutputStream("file.txt");
______;

catch(Exception e)

e.printStackTrace();


【参考答案】

new byte
System.in.read(buffername)
f.write(buffername......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
热门 试题