问答详情
源自:6-2 transient及ArrayList源码分析

问大家一段代码,代码如下,目的是写入三行文字

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();
}
}
}

提问者:lynhao 2015-05-23 10:22

个回答

  • 好帮手慕珊
    2015-05-25 10:27:31

    是问这段代码有没有问题吗,你这样写进去的文字应该是乱码吧