找不到文本文件,java 文件 I/O 错误
could not find text file, java file I/O error
不知道为什么这不会读取我保存在同一目录中的 txt 文件。它编译得很好,但是当我在 cmd ln 中输入 java BlindfoldsAside
时,它说它无法找到或加载我的主要 class BlindfoldsAside。据我所知,案例都是正确的,所有内容都在正确的文件路径中,所以我不确定哪里出错了!
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
尝试将 txt 文件移动到项目根文件夹中。那应该没有问题。让我知道是否有什么变化或者它是否工作正常。
不知道为什么这不会读取我保存在同一目录中的 txt 文件。它编译得很好,但是当我在 cmd ln 中输入 java BlindfoldsAside
时,它说它无法找到或加载我的主要 class BlindfoldsAside。据我所知,案例都是正确的,所有内容都在正确的文件路径中,所以我不确定哪里出错了!
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
尝试将 txt 文件移动到项目根文件夹中。那应该没有问题。让我知道是否有什么变化或者它是否工作正常。