windows的记事本,那字符串是不是应该这样写:String source = "Now is the time for all good men"+char(13)+char(10)+ "to come to the aid of their country"+char(13)+char(10)+"and pay their due taxes.";
怎么使能将写入windows 记事本中的字符,换行呢?
String source = "Now is the time for all good men\n\r"+ "to come to the aid of their country\n\r"+ "and pay their due taxes.";
to myhotsun(科科)不行啊,出现了两个小黑块,还是不换行...
已经帮你运行: import java.io.*; class Temp4 {public static void main(String[] args) {String source = "Now is the time for all good men"+'\n'+ "to come to the aid of their country"+'\n'+ "and pay their due taxes.";byte b[] = source.getBytes(); try{FileOutputStream f0 = new FileOutputStream("d:/file1.txt"); f0.write(b); f0.close(); } catch(FileNotFoundException exp1) {System.out.println("file not found"); System.exit(1); } catch(IOException exp2) {System.out.println("IOException occured"); System.exit(1); } }}
上面程序中修改一下: String source = "Now is the time for all good men\n\r"+'\n'+ "to come to the aid of their country\n\r"+'\n'+ "and pay their due taxes.";
流式的写对raw byte实现比较好如image data等
在SPEC中对characters的写建议用FileWriter
"to come to the aid of their country"+char(13)+char(10)+"and pay their due taxes.";
"to come to the aid of their country\n\r"+
"and pay their due taxes.";
import java.io.*;
class Temp4
{public static void main(String[] args)
{String source = "Now is the time for all good men"+'\n'+
"to come to the aid of their country"+'\n'+
"and pay their due taxes.";byte b[] = source.getBytes();
try{FileOutputStream f0 = new FileOutputStream("d:/file1.txt");
f0.write(b);
f0.close();
}
catch(FileNotFoundException exp1)
{System.out.println("file not found");
System.exit(1);
}
catch(IOException exp2)
{System.out.println("IOException occured");
System.exit(1);
}
}}
String source = "Now is the time for all good men\n\r"+'\n'+
"to come to the aid of their country\n\r"+'\n'+
"and pay their due taxes.";