用我的方法好了,我给一个我自己写的例子:
import java.io.*;
class FileCopy
{
public static void main(String[] args) 
{
String readedString;
FileInputStream fis;
StringBuffer sb = new StringBuffer();
try{
fis = new FileInputStream("filename.txt");
int readChar;
while(true){
readChar = fis.read();
if(readChar==-1) break;
sb.append((char)readChar);
}
}catch(FileNotFoundException e){
}
catch(IOException e){
}
readedString = sb.toString();
System.out.println(readedString);
}
}
文件内容返回到字符串readedString中。