• Post Reply Bookmark Topic Watch Topic
  • New Topic

read file pullzed

 
eastjy eastjy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
class ReadFile
{
public static void main(String args[]) throws Exception
{
//String ss="d:\\Temp\\Test.java";
//File readFile = new File(ss);
StringBuffer stfDir = new StringBuffer();
char ch = (char)System.in.read();
while( ch != '\n')
{
stfDir.append(ch);
ch = (char)System.in.read();
}
String ss = stfDir.toString();
File readFile = new File( ss );
if( readFile.isFile() &&readFile.canWrite() && eadFile.canRead())
{
RandomAccessFile rafFile =
new RandomAccessFile(readFile,"rw");
while(rafFile.getFilePointer()<rafFile.length())
System.out.println(rafFile.readLine());
rafFile.close();
}
else
System.out.println("File cannot be read!");
}
}
run input d:\temp\test.java(the file exists),the result is: File cannot be read!
but this file compile and run in JBuilder,the result is OK.
and I use the sentence which is commented,the result is right not only in JBuilder but JDK self.
another is the sentense list underside in java is not be allowed??
while(char ch = (char)System.in.read())!='\n')
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!