小问题>?????

weidongdong 2003-10-17 11:44:37
我想用以下程序读取e;/jf/wdp1 路径下的文本文件:file.txt 数据
在file.txt 里存有数据:weidongping hello
但读出来后用System.out.println("String read: "+((ByteBuffer) bytBuff.flip ()).asCharBuffer().toString());显示出来时却是一些看不懂的字.
请问这是为什么???


import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class TryRead
{
public static void main(String[] args)
{
File aFile=new File("e:/jf/wdp1/file.txt");
FileInputStream inFile=null;

try{
inFile=new FileInputStream(aFile);

}catch(IOException e){System.out.println("Usage:a exception catched");System.exit(0);}

FileChannel inChannel=inFile.getChannel();
ByteBuffer bytBuff=ByteBuffer.allocate(48);
try{
while(inChannel.read(bytBuff)!=-1)
{
System.out.println("String read: "+((ByteBuffer) bytBuff.flip ()).asCharBuffer().toString());
bytBuff.clear();
}

System.out.println("EOF readed");
inFile.close();

}catch(IOException e){e.printStackTrace(System.err);System.exit(1); }

}

}




...全文
33 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxh512 2003-10-17
  • 打赏
  • 举报
回复
是不是字体的问题
再把文件的字体转化一下

62,614

社区成员

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

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