为什么不换行

wwwasp 2004-06-22 12:00:54
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();

FileOutputStream f0 = new FileOutputStream("d:/file1.txt");
f0.write(b);
f0.close();

将以上字符串,写进文本文件中其中的'\n'为什么不换行呢,而是出现一个小黑块
...全文
127 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wulemale 2004-06-23
  • 打赏
  • 举报
回复
上面程序中修改一下:
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.";
wulemale 2004-06-23
  • 打赏
  • 举报
回复
已经帮你运行:
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);
}
}}
wwwasp 2004-06-23
  • 打赏
  • 举报
回复
to myhotsun(科科)

不行啊,出现了两个小黑块,还是不换行...
myhotsun 2004-06-23
  • 打赏
  • 举报
回复
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.";
wwwasp 2004-06-23
  • 打赏
  • 举报
回复
怎么使能将写入windows 记事本中的字符,换行呢?
ecaol 2004-06-22
  • 打赏
  • 举报
回复
"/n/r"
shuneng 2004-06-22
  • 打赏
  • 举报
回复
你试试FileWriter吧
流式的写对raw byte实现比较好如image data等
在SPEC中对characters的写建议用FileWriter
happyegg 2004-06-22
  • 打赏
  • 举报
回复
看你在什么系统下用什么文本编辑器打开的了。在unix下char(10)就可以换行。在windows下用ultraedit和editplus打开也可以换行,但是用windows的打开要char(13) char(10)才能显示换行。这是文本编辑器显示的问题,而不是你的内容问题。
wwwasp 2004-06-22
  • 打赏
  • 举报
回复
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.";

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧