非常急 JAVA考试 在线等

来源:百度知道 编辑:UC知道 时间:2024/05/05 23:48:59
使用FileOutputStream 把命令行输入的数据添加到某个已存在的文件中

考试题目 在线等

import java.io.*;

class FSODemo
{
public static void main(String args[]) throws Exception
{
String str;
InputStreamReader stdin = new InputStreamReader(System.in);//键盘输入
BufferedReader bufin = new BufferedReader(stdin);
try
{
System.out.print ("请输入字符: ");
str = bufin.readLine();
byte buf[] = str.getBytes();
FileOutputStream f=new FileOutputStream("file.txt");
f.write(buf);
f.close();
System.out.println("文本已经成功写入文件!");
}
catch(IOException E)
{
System.out.println("发生I/O错误!!!");
}

}
}

改好了,也测试过了,就是那个分号有问题