好的。大虾请看:
import Java.io.*;
public class ReadFromFile
{
public static void main(String args[])
{
char ch;
System.out.println("please input a directory hat the file located in:");
StringBuffer stfDir=new StringBuffer();
While((ch=(char)System.in.read())!='\n')
{
strDir.appendChar(ch);
}
File dir=new File(strDir.toString());
System.out.println("please input the name of the file to read");
StringBuffer strFilename=new StringBuffer();
While((ch=(char)System.in.read())!='\n')
{
strFilename.appendChar(ch);
}
File readFrom=new File(dir,strFilename.toString());
if (readFrom.isFile() && readFrom.canWrite() && readFrom.canRead())
{
RandomAccessFile rafFile=new RandomAccessFile(ReadFrom,"rw");
while(rafFile.getFilePointer()<rafFile.length())
System.out.println(rafFile.readLine())
rafFile.close();
}
else
{
System.out.println("File can not be read!");
}
}
}