This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Reading a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading a text file" Watch "Reading a text file" New topic
Author

Reading a text file

Mohamed Manas
Greenhorn

Joined: Jun 02, 2008
Posts: 24
hi,
I am trying to read data from a text file named "myFile.txt".
Although the text file is in the same directory with the class JVM throws the FileNotFoundException.
I've added the code here. Is there a flow in the coding?
Thanks in advance.


It is better to make mistakes now and on purpose than later and accidentally...
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8834
    
    7

By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.

java.io.File

Try invoking getCanonicalPath() on the File instance to see where exactly the JVM is looking.
[ June 06, 2008: Message edited by: Joe Ess ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading a text file
 
Similar Threads
command line arguments for a file
Pls HELP! How to count the number of row in file?
opening and saving using JFileChooser
Pause / Sleep in Java
Read from file and display nonduplicate words in ascending order.