0

not sure why this won't read my txt file saved in the same directory. it compiled just fine but then when i enter java BlindfoldsAside into the cmd ln, it says it cannot find or load my main class BlindfoldsAside. The case is all correct as far as I can see and everything is in the right file path, so I'm not sure where i went wrong!

package blindfoldsaside;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class BlindfoldsAside {
    public static void main (String[] args) {
        Scanner scannerIn = null;
        FileInputStream in = null;
        BufferedReader inputStream = null;
        int fileChar; //character's int equivalent
        String fileLine;
        try {
            // FileInputStream calls the txt file
            in = new FileInputStream("blindfoldsaside.txt");
            System.out.println("These lyrics tell the story of a woman, named Kezia, who is" + 
        " \nbeing put to death after being forced into prostitution. This song is from the prison" + 
        " \nguard's (who is also the executioner) point of view. I hope you enjoy.");
            // this reads the file one char at a time
            while ((fileChar = in.read()) != -1) {
                System.out.print((char) fileChar);
            }// end while
            System.out.println(""); //separates the file output
            System.out.println("");
            System.out.println("This song was written by Arif Mirabdolbaghi (bassist) and performed by " + 
        " Protest the Hero. This song appears on the band's first full length album, Kezia, " + 
        " released in their native country (Canada) on August 30th, 2005 and to the U.S. on " + 
        " April 4th, 2006. This is the 6th track on the album.");
        } catch (IOException io) {
            System.out.println("File IO exception" + io.getMessage());
        } finally {
            try {
                if (in != null) {
                    in.close();
                }// end if
                if (inputStream != null) {
                    inputStream.close();
                }// end if
            } catch (IOException io) {
                System.out.println("There was a problem closing your files" + io.getMessage());
            }// end catch
        }// end finally
    }// end main
}// end class
  • Did you compile correctly the java file? are you running it inside the folder where the compiled file is located? Where is the file `blindfoldsaside.txt`? Which IDE you're using? – goncalopinto Mar 07 '16 at 01:29
  • Everything compiled and blindfoldsaside.txt is saved in the same file path as the compiled java file. I've been using netbeans and this is the output: `File IO exception blindfoldsaside.txt (The system cannot find the file specified) BUILD SUCCESSFUL (total time: 0 seconds)` – 3monkeys1gorilla Mar 07 '16 at 01:41
  • Try a test of outputting the current execution directory path to see where it might be looking for the file. – souldzin Mar 07 '16 at 01:58
  • try moving the txt file into the project root folder. that should work with no issues. Lest me know if something changed or if it worked fine. – goncalopinto Mar 07 '16 at 02:01
  • @goncalopinto thank you very much for the info, I just made another folder moved everything to include the txt file in to it and poof it magically worked. if i could check mark your comment i would! – 3monkeys1gorilla Mar 07 '16 at 02:21
  • I put it as an answer, now you should be able to do it. Cheers. – goncalopinto Mar 07 '16 at 02:25
  • done and done, thank you again! – 3monkeys1gorilla Mar 07 '16 at 02:29

1 Answers1

1

Try moving the txt file into the project root folder. that should work with no issues. Lest me know if something changed or if it worked fine.

goncalopinto
  • 433
  • 2
  • 8