aspose file tools*
The moose likes Beginning Java and the fly likes The system can only find one of the two files specified Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The system can only find one of the two files specified" Watch "The system can only find one of the two files specified" New topic
Author

The system can only find one of the two files specified

Claire Saunders
Greenhorn

Joined: Sep 29, 2009
Posts: 5
Hello all!

I'm in a programming class and we're writing our first program with scanners. I'm using two different text files. Unfortunately, only one of them works-- the other is consistently giving me this error message:

Exception in thread "main" java.io.FileNotFoundException: AccInfo.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at comp401pkg.AnalyzeAccFootball.readTeamInfo(AnalyzeAccFootball.java:18)
at comp401pkg.AnalyzeAccFootball.main(AnalyzeAccFootball.java:12)

The file is saved in the same location as the java and the working text file, though, so it should work fine. Or so I thought. Any suggestions as to what could be wrong would be greatly appreciated!

Full code, in case you need it:
package comp401pkg;
import static java.lang.System.out;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class AnalyzeAccFootball {
private static AccFootballTeam[] team = new AccFootballTeam[12];

public static void main(String[] args) throws FileNotFoundException {
readTeamInfo();
printTeams();
}


public static void readTeamInfo() throws FileNotFoundException {
Scanner input = new Scanner(new File("AccInfo.txt"));
for (int i = 0; i < 12; i++) {
String line = input.nextLine();
String[] word = line.split(";");
team[i] = new AccFootballTeam(word[0], word[1], word[2] );
}
}


public static void readWeekInfo() throws FileNotFoundException {
Scanner input = new Scanner(new File("Week1.txt"));
for (int i = 0; i < 12; i++) {
String line = input.nextLine();
String[] word = line.split(";");
for (int k = 0; k < 12; k++) {
if (team[k].abbreviation==word[1]) {
team[k].score = word[2];
team[k].opponentScore = word[3];
}
else
if (team[k].abbreviation==word[4]) {
team[k].score = word[3];
team[k].opponentScore = word[2];
}
}
}
}


public static void printTeams() {
for( int i = 0; i < 12; i++ ) {
out.println(team[i].toString() );
}
}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Check the permissions on the file - FileNotFoundException is also thrown if the application doesn't have access rights to a file.


Ping & DNS - my free Android networking tools app
Claire Saunders
Greenhorn

Joined: Sep 29, 2009
Posts: 5
Ulf Dittmer wrote:Check the permissions on the file - FileNotFoundException is also thrown if the application doesn't have access rights to a file.

I've tried swapping the files, just to check-- AccInfo.txt gives me no error messages in the second scanner, and Week1.txt gives the same error message in the first. So I do have access rights to it. Thanks for the suggestion, though!


EDIT-- I realized why the second file wasn't giving me any error messages. I had no "readWeekInfo()" under main. Now both give me the error message.

So how do I check if I have access rights to the file?
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
put the files in class path location and see whether it works?
Claire Saunders
Greenhorn

Joined: Sep 29, 2009
Posts: 5
Rahul.p Kumar wrote:put the files in class path location and see whether it works?

=D That worked! At last!

Of course now I have to deal with all the other errors that I haven't noticed 'til now. Such is life. :P
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
java files are not used by jvm to run the main class, these are compiled class files which are used and so all path should be with reference to class files.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
put the files in class path location and see whether it works?

This sounds wrong. Files are not loaded from the classpath, so if this made a difference then something else is likely not right.

team[k].abbreviation==word[1]

Strings are not compared using the "==" operator, they're compared using the "equals" method. This is a bug waiting to happen.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Claire, next time please Use Code Tags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Consider Paul's rocket mass heater.
 
subject: The system can only find one of the two files specified