如何读取文件内容

bitterghost 2003-12-30 04:43:29
如何读取文件内容
...全文
45 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiger_wkh52741 2004-01-05
  • 打赏
  • 举报
回复
使用RandomAccessFile ,不错!
bitterghost 2004-01-05
  • 打赏
  • 举报
回复
up
Leemaasn 2003-12-31
  • 打赏
  • 举报
回复
方法很多。

基本上就是灵活运用java。io这个包

其实,我推荐能使用RandomAccessFile 是最好的。



将“流氓无赖”测试到底。。。
——始于2003年7月


树欲止而风不停,行云流水匆匆去;
树梢蚂蚱凭空望,江边浪花碎巨石;



支持“流金岁月”!!!
发送框,少个“右键菜单,选择粘贴”;
——2003年12月24日am

^@^
bitterghost 2003-12-31
  • 打赏
  • 举报
回复
还有别的方法么
CoolAbu 2003-12-30
  • 打赏
  • 举报
回复
读文件
String modpath="c:\\b.txt";
RandomAccessFile fin=new RandomAccessFile(modpath,"r");
String rLine;
long filePointer=0;
long length=fin.length();
while(filePointer<length)
{
rLine=fin.readLine();
System.out.println(rLine);
filePointer=fin.getFilePointer();
}
fin.close();

写文件
String fullPath="c:\\b.txt";
tmpContent="Pinch me";
RandomAccessFile fout=new RandomAccessFile(fullPath,"rw");
fout.writeBytes(tmpContent);
fout.close();
supersunyi 2003-12-30
  • 打赏
  • 举报
回复
file_文件
FileInputStream reader = new FileInputStream(file_);
int size = (new Long(file_.length())).intValue();
filedata_ = new byte[size];
reader.read(filedata_);
reader.close();

最基本的写法,读入字节

62,612

社区成员

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

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