0

なぜこれが同じディレクトリに保存された私のtxtファイルを読み取らないのかわかりません。それは問題なくコンパイルさjava BlindfoldsAsideれましたが、cmd lnに入ると、メインクラスの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
4

1 に答える 1

1

txt ファイルをプロジェクトのルート フォルダーに移動してみてください。問題なく動作するはずです。何かが変わったのか、それともうまくいったのか教えてください。

于 2016-03-07T02:25:20.810 に答える