文件输出时,多了几个方块,奇怪,大家帮忙~~~

cf527085608 2009-07-31 08:47:15
import java.io.*;
//号码薄示例
class IOUse
{
static FileOutputStream myFileOutputStream;
public static final int lineLength=81;

public static void main(String args[]) throws IOException
{
byte[] phone=new byte[lineLength];
byte[] name=new byte[lineLength];
//实例化FileOutputStream对象
myFileOutputStream=new FileOutputStream("e:\\aaa.txt");

while(true)
{
System.out.println("Please enter a name(enter 'done' to quit):");
//从终端读取数据后向FileOutputStream对象写入数据
readLine(name);
if("done".equalsIgnoreCase(new String(name,0,0,4)))
{
break;
}
System.out.println("Enter the phone number:");
readLine(phone);
for(int i=0;phone[i]!=0;i++)
{
myFileOutputStream.write(phone[i]);
}
myFileOutputStream.write(',');
for(int i=0;name[i]!=0;i++)
{
myFileOutputStream.write(name[i]);
}
myFileOutputStream.close();
}
}

private static void readLine(byte line[])throws IOException
{
int i=0,b=0;
while((i<(lineLength-1))&&((b=System.in.read())!='\n'))
{
line[i++]=(byte)b;
}
line[i]=(byte)0;
}
}


Please enter a name(enter 'done' to quit):
caofeng
Enter the phone number:
12345
Please enter a name(enter 'done' to quit):
done


在我的文件里面输出的是:caofeng ,12345 不知道为什么,我复制粘贴到这里面的时候,后面的黑色方块又没了,但在我文件里面canfeng和12345后面是分别有一个黑色的方块的,谁给我解释下,谢谢了~~~
...全文
80 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigbug9002 2009-07-31
  • 打赏
  • 举报
回复
你复制到这里时,你没有发现换行了?
bigbug9002 2009-07-31
  • 打赏
  • 举报
回复
运行了一遍,确实是回车符'\n'
老张-AI 2009-07-31
  • 打赏
  • 举报
回复
回车符
冰思雨 2009-07-31
  • 打赏
  • 举报
回复
那个方块是回车符。
bigbug9002 2009-07-31
  • 打赏
  • 举报
回复
那个是回车符吧

62,621

社区成员

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

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