问大家一段代码,代码如下,目的是写入三行文字
public void writeFile()throws IOException
{
int i =1;
while(i<4)
{
System.out.println("请输入内容");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
byte[] b = str.getBytes();
//String newline = System.getProperty("line.separator");
FileOutputStream out = new FileOutputStream("/Users/a/Documents/workspace/I.O/src/a.txt",true);
//out.write(newline.getBytes());
out.write(b);
//System.out.println();
out.flush();
out.close();
++i;
}
}
public static void main(String[] args)
{
try{
new Exam1().writeFile();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}