class MyFile
{
public MyFile()
{}
public void write(String strName,
String strSex,
String strMobilePhone,
String strOfficePhone,
String strHousePhone,
String strAddress)
{
FileOutputStream fos=null;
try
{
fos=new FileOutputStream("message.txt",true);
}
catch(Exception ex)
{
ex.printStackTrace();
}
try{
fos.write((strName+" "+strSex+" "+strMobilePhone+" "+strOfficePhone+" "+strHousePhone+" "+strAddress+"\\u000a").getBytes());
fos.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args)
{
MyFile mf=new MyFile();
mf.write();
}}
编译的时候总是有错误呀 怎么回事难道换行的转义字符不是 \n \u000a 这两个到底是写哪个??? 疯了。
你想写入文本文件给别人看的话,不要用\n或者newline(),因为记事本这些普通文本编辑器是不认识转义字符的,只能显一个黑方块
BufferedWriter bw = new BufferedWriter(new FileWriter("filename"));
bw.write("test");
bw.newLine();
BufferedWriter bw = new BufferedWriter(new FileWriter("filename"));
bw.write("test");
bw.newLine();