各位高手,我的java教程里的有段代码是这样的,的确能编译运行,但是我搞不懂catch语句块内的return后面什么也没有是什么意思,而且如果我把两个rentun删了,会出现初始化变量raf报错信息,请问是为什么?import java.io.*;
class RandomAccessData
{
public static void main(String[] args) throws IOException
{
double d;
RandomAccessFile raf; try
{
raf = new RandomAccessFile("record.dat", "rw");
}
catch (FileNotFoundException e)
{
System.out.println("Can't open file");
return;
} for (int i = 0; i < 10; i++)
{
try
{
raf.writeDouble((double)i);
}
catch (IOException e)
{
System.out.println("Error writing to file");
return;
}
} try
{
for (int i = 0; i < raf.length()/8; i++)
{
raf.seek(i * 8);
d = raf.readDouble();
System.out.println("value(" + (i + 1) + ") = " + d);
}
}
catch (IOException e)
{
System.out.println("Error seeking or reading");
}
raf.close();
}
}
class RandomAccessData
{
public static void main(String[] args) throws IOException
{
double d;
RandomAccessFile raf; try
{
raf = new RandomAccessFile("record.dat", "rw");
}
catch (FileNotFoundException e)
{
System.out.println("Can't open file");
return;
} for (int i = 0; i < 10; i++)
{
try
{
raf.writeDouble((double)i);
}
catch (IOException e)
{
System.out.println("Error writing to file");
return;
}
} try
{
for (int i = 0; i < raf.length()/8; i++)
{
raf.seek(i * 8);
d = raf.readDouble();
System.out.println("value(" + (i + 1) + ") = " + d);
}
}
catch (IOException e)
{
System.out.println("Error seeking or reading");
}
raf.close();
}
}
如果不加 return 的话,即使出现了异常,后面的循环也会继续执行下去.
RandomAccessFile raf = null;