感觉书上的没有啥意义,就自己写了一个
可以满足的功能有,新建一个文件,(需要输入文件路径和文件名)
然后就是写入文字。
写入状态下输入off退出去。
代码如下
但是还有一个弱点 也就是 不能换行
import java.io.*;
import java.util.Scanner;
public class FileWr {
public static void main(String arg[]) throws IOException{
String dir =null;
String FileName = null;
Scanner sca = new Scanner(System.in);
System.out.println("请输入路径");
dir=sca.nextLine();
System.out.println("请输入文件名");
FileName=sca.nextLine();
File f = new File(dir,FileName);
FileOutputStream fileout = new FileOutputStream(f,true);
byte []b = null;
String text = null;
System.out.println("请输入文件内容,输入off关闭");
while(!(text=sca.nextLine()).equals("off"))
{
b=text.getBytes();
fileout.write(b);
}
fileout.close();
}
}