写了下面一段代码,感觉没问题可就是编译老不通过:
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 错误处理已完成。
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 错误处理已完成。
用eclipse看到的错误,没有这个构造方法
The constructor RandomAccessFile(String) is undefined源代码定义了这2个实现:
public RandomAccessFile(String name, String mode)
public RandomAccessFile(String name, String mode)
定义mode为读写应该是可以用的
public RandomAccessFile(File file, String mode)
public RandomAccessFile(String name, String mode)