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
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.