-1

I've tried directly linking using the entire path but that hasn't solved it either.

package eliza;

import java.io.*;

public class Eliza {

public static void main(String[] args) throws IOException {
    String inputDatabase = "src/eliza/inputDataBase.txt";
    String outputDatabase = "src/eliza/outputDataBase.txt";
    Reader database = new Reader();

    String[][] inputDB = database.Reader(inputDatabase);
    String[][] outputDB = database.Reader(outputDatabase);

}
}

Here is the reader class:

package eliza;

import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Reader {

public String[][] Reader(String name) throws IOException {
    int length = 0;
    String sizeLine;

    FileReader sizeReader = new FileReader(name);
    BufferedReader sizeBuffer = new BufferedReader(sizeReader);

    while((sizeLine = sizeBuffer.readLine()) != null) {
        length++;
    }

    String[][] database = new String[length][1];

    return (database);
}
}

Here's a photo of my directory. I even put these text files in the "eliza" root folder: here

Any ideas?

4

4 回答 4

2

Since you are using an IDE, you need to give the complete canonical path. It should be

String inputDatabase = "C:\\Users\\Tommy\\Desktop\\Eliza\\src\\eliza\\inputDataBase.txt";
String outputDatabase = "C:\\Users\\Tommy\\Desktop\\Eliza\\src\\eliza\\outputDataBase.txt";

The IDE is probably executing the bytecode from its bin folder and cannot find the relative reference.

于 2013-09-14T05:46:30.430 回答
0

give the exact path like

String inputDatabase = "c:/java/src/eliza/inputDataBase.txt";
于 2013-09-14T05:43:25.757 回答
0

you have not given the correct path, Please re check

try

{BASE_PATH}+ "Eliza/src/inputDataBase.txt"
于 2013-09-14T05:44:40.860 回答
0

The source directory tree isn't generally present during execution, so files that are required at runtime shouldn't be put there ... unless you're going to use them as resources, in which case their pathname is relative to the package root, and does not begin with 'src', and the data is accessed by a getResourceXXX() method, not via a FileInputStream.

于 2013-09-14T07:44:32.470 回答