cjy
发贴: 7
积分: 0
|
于 2004-09-14 14:36
各位大侠,帮小弟看看这段代码怎么了?
import java.util.*; import java.io.*; class CFileExample2 { private String s=""; private RandomAccessFile f1=new RandomAccessFile("file1.txt","rw"); private RandomAccessFile f2=new RandomAccessFile("file2.txt","rw"); void fileLink() { s=f1.readLine()+f2.readLine(); char c[]=s.toCharArray(); Arrays.sort(c); FileOutputStream out=new FileOutputStream("new.txt"); for(int i=0;i<c.length;i++) { out.write(c[i]); } out.close(); f1.close(); f2.close(); } } public class FileExample2 { public static void main(String[] args)throws IOException { CFileExample2 f=new CFileExample2(); f.fileLink(); } } FileExample2.java:6: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown private RandomAccessFile f1=new RandomAccessFile("file1.txt","rw"); ^ FileExample2.java:7: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown private RandomAccessFile f2=new RandomAccessFile("file2.txt","rw"); ^
我的file1.txt各file2.txt文件都在同一文件夹下,并且每个文件只有一行字母而已。我觉得我的声明没有错的嘛?why?
why edited on 2004-09-14 18:56
|