aspose file tools*
The moose likes Cattle Drive and the fly likes SortNames FileNotFoundException??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "SortNames FileNotFoundException???" Watch "SortNames FileNotFoundException???" New topic
Author

SortNames FileNotFoundException???

debbie shifferd
Greenhorn

Joined: Oct 16, 2003
Posts: 11
I am getting a FileNotFoundException when I execute SortNames. The problem is that the file is there.
I have both the source file and the "names.txt" in a directory called,
C:\JavaExercises
I am executing the following code:
TextFileIn in = new TextFileIn("names.txt");
boolean done = false ;
while ( ! done ) {
String s = in.readLine();
if ( s == null ) {
done = true ;
}
else {
System.out.println( s );
}
}
in.close();
The "names.txt" file is notmarked "read only". I don't know why the program can't find the file. Any suggestions?
Greg Neef
Ranch Hand

Joined: Jun 16, 2003
Posts: 82
Seems like that ought to work. Have you tried specifying the full file path and name to try to eliminate pathing problems?
TextFileIn in = new TextFileIn( "C:\JavaExercises\names.txt" ) ;
Just a thought.


SCJP 1.4
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Just for fun, try using the full path to the file. If that works, then you know you have a pathing issue. What command are using to run the program, and are you running it from within the directory that the names.txt is in?
[ October 21, 2003: Message edited by: jason adam ]
debbie shifferd
Greenhorn

Joined: Oct 16, 2003
Posts: 11
I had tried that already and it creates a checked exception. "illegal escape character".
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Use \\ instead of just \, or you can use / instead
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1190
This is probably a really dumb comment, but are you sure the file name and extension are right? If you're using notepad to write your code, it may have added an extension to the file name without you noticing?
debbie shifferd
Greenhorn

Joined: Oct 16, 2003
Posts: 11
The good news is that the following did work:
TextFileIn in = new TextFileIn("C:\\JavaExercises\\names.txt");
Thanks to all of you
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Glad it's working Debbie. Sounds like a pathing problem.
Even if your class and the text file are in the same location, if you are running the application like
d:\java -cp c:\JavaExercises SortNames
Then the application will look for the file on the D:\ drive, NOT in the folder your application is in.
To test where the JVM is looking for the file, put the following lines at the beginning of the application and check out the output
File f = new File( "test.txt" );
System.out.println( f.getAbsolutePath() );
test.txt does not actually have to exist for this to work.
[ October 21, 2003: Message edited by: jason adam ]
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401

Oh the cow in the meadow goes "moo"
Oh the cow in the meadow goes "moo"
Then the farmer hits him on the head and grinds him up
And that's how we get hamburgers.
Nowwwww chickens!

Do your animals enjoy this jingle Jason?


doco
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1190
Okay, let's take this one step further. I went back to check out SortNames to see if I could figure out what was up, and I discovered that I couldn't compile anything because I had installed a newer version of the JDK since I did this assignment. I had to edit my PATH, which I did, and now Windows can find the compiler. (YAY) But, now I am getting this error message when I try to compile:
C:\java>javac SortNames.java
SortNames.java:14: cannot access TextFileIn
bad class file: .\TextFileIn.class
class file contains wrong class: com.javaranch.common.TextFileIn
Please remove or make sure it appears in the correct subdirectory of the classpath.
TextFileIn file = new TextFileIn( "list.txt" );
^
This file is in the com.javaranch.common folder where it belongs, and I don't understand what the problem is. My classpath looks like this:
@SET CLASSPATH=C:\PROGRA~1\PHOTOD~1.1\ADOBEC~1;C:\j2sdk1.3.1_09\lib;.;
C:\java;C:\j2sdk1.3.1_09\bin;C:\j2sdk1.3.1_09\jre\bin;C:\j2sdkee1.3.1\lib\j2ee.jar;
C:\mysql-connector-java-2.0.14\mysql-connector-java-2.0.14-bin.jar;C:\XT\xt.jar;
C:\XML\SAX;C:\XML\xp\xp.jar;
The classpath is a nightmare, but I don't want to edit it without knowing exactly what I'm doing. Should I put C:\java\com\javaranch\common; in my classpath?

[ October 21, 2003: Message edited by: Carol Murphy ]
[ October 24, 2003: Message edited by: Jim Yingst ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Originally posted by Carol Murphy:
My classpath looks like this:
@SET CLASSPATH=C:\PROGRA~1\PHOTOD~1.1\ADOBEC~1;C:\j2sdk1.3.1_09\lib;.;
C:\java;C:\j2sdk1.3.1_09\bin;C:\j2sdk1.3.1_09\jre\bin;C:\j2sdkee1.3.1\lib\j2ee.jar;
C:\mysql-connector-java-2.0.14\mysql-connector-java-2.0.14-bin.jar;C:\XT\xt.jar;
C:\XML\SAX;C:\XML\xp\xp.jar;

I recommend that you remove:
C:\j2sdk1.3.1_09\lib
C:\j2sdk1.3.1_09\bin
C:\j2sdk1.3.1_09\jre\bin
from your CLASSPATH. The bin directories belong in your PATH, but are not necessary in your CLASSPATH.

Didn't you put the com.javaranch stuff in your classpath to compile the log update stuff?
[ October 24, 2003: Message edited by: Jim Yingst ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1190
I thought I had done that, but I made so many changes and unchanges when I was sorting that mess out, that I must have removed it again. What ended up working for me was unzipping the JavaRanchCommon.zip file into my C:\java folder. That worked. Perhaps I need to put something like C:\java\com\javaranch\common;
in my classpath? I'm a little irritated with my system these days. My son installled some stupid game, and now my desktop has these huge icons, and everything displays so huge, I can't see a whole page like I used to. I tried all the tricks I know to put things back to normal, but nothing seems to be working. My desktop looks like it belongs to a little kid, everything is so large! Enough ranting. Back to work!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
I think that one of the main points of the first OOP assignment is to figure out how to do this. Perhaps it would be best if you redo that assignment and send it via email to me at marilyn@javaranch.com
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1190
A little remedial cattle punching? Okay, I'll go back to school! If I figured this out once, I should be able to do it again, right? I knew saving my notes would come in handy. I just have to remember where I put them!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SortNames FileNotFoundException???
 
Similar Threads
SortNames..
help needed with file reading in program.
SortNames
SortNames