诚心请教

lihaifeng0412 2007-09-27 10:14:04
写了下面一段代码,感觉没问题可就是编译老不通过:
import java.io.*;
public class random_file
{ public static void main(String[] args)
{ int data_arr[]={12,31,56,23,27,1,43,65,4,99};
try { RandomAccessFile randf=new RandomAccessFile ("temp.txt");

for (int i=0;i<data_arr.length;i++)
randf.writeInt(data_arr[i]);
for(int i=data_arr.length-1;i>=0;i--)
{ randf.seek(i*4);
System.out.println(randf.readInt()); }
randf.close();
}catch (IOException e)
{ System.out.println("File access error: "+e);} } }


编译提示:
E:\JavaChengXu\random_file.java:5: 找不到符号
符号: 构造函数 RandomAccessFile(java.lang.String)
位置: 类 java.io.RandomAccessFile
try { RandomAccessFile randf=new RandomAccessFile ("temp.txt");
^
1 错误

处理已完成。

...全文
76 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qybao 2007-09-27
  • 打赏
  • 举报
回复
RandomAccessFile randf=new RandomAccessFile ("temp.txt", "rw");
lihaifeng0412 2007-09-27
  • 打赏
  • 举报
回复
我怎么这么不小心啊,感谢楼上的朋友啊!
宋玮-深圳 2007-09-27
  • 打赏
  • 举报
回复
。。2楼那个帖我打错字了,应该是这2个构造器
public RandomAccessFile(File file, String mode)
public RandomAccessFile(String name, String mode)
宋玮-深圳 2007-09-27
  • 打赏
  • 举报
回复
RandomAccessFile randf = new RandomAccessFile("temp.txt","rw");
定义mode为读写应该是可以用的
宋玮-深圳 2007-09-27
  • 打赏
  • 举报
回复
try { RandomAccessFile randf=new RandomAccessFile ("temp.txt");
用eclipse看到的错误,没有这个构造方法
The constructor RandomAccessFile(String) is undefined

源代码定义了这2个实现:
public RandomAccessFile(String name, String mode)
public RandomAccessFile(String name, String mode)

62,623

社区成员

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

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