This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I want to check if the file I'm trying to read is empty and exit program if it's empty. I've tried if(bis.readLine().length()==0) System.out.print("File is empty!"); } else... and if(bis.readLine()==null) System.out.print("File is empty!"); } else... but it's not working the way I want. If i try to read an empty file it doesn't print out the message i like.
well you can use the function of File class called Length ------------------------------------------- public long length() Returns the length of the file denoted by this abstract pathname. Returns: The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist Throws: SecurityException - If a security manager exists and its SecurityManager.checkRead(java.io.FileDescriptor) method denies read access to the file ----------------------------------------------- now if(myfile.Length()==0) //print file empty let me know if this works [ February 19, 2002: Message edited by: Jigar Gosar ]
kristian jarvi
Greenhorn
Joined: Jan 19, 2002
Posts: 9
posted
0
Originally posted by Jigar Gosar: well you can use the function of File class called Length ------------------------------------------- public long length() Returns the length of the file denoted by this abstract pathname. Returns: The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist Throws: SecurityException - If a security manager exists and its SecurityManager.checkRead(java.io.FileDescriptor) method denies read access to the file ----------------------------------------------- now if(myfile.Length()==0) //print file empty let me know if this works [ February 19, 2002: Message edited by: Jigar Gosar ]
Hi, Jigar I can't get it to work.it doesn't print the message i want, just an empty line in command promt!!