简体   繁体   中英

Where to put a .txt file in java that it can be read using eclipse?

Java isn't able to read the file konto.txt that i put in the src folder next to all .java files. where do I have to put the file in order that it can be read? or do I have to change the main method? I did it first in bluej and it worked perfectely with the existing source code.

public static void main (String[] args) throws java.io.IOException {

    String filename = "konto.txt";
    ArrayList kontoliste = null;
    FileInputStream fis = null;
    ObjectInputStream in = null;
    try{
        fis = new FileInputStream(filename);
        in = new ObjectInputStream(fis);
        kontoliste = (ArrayList) in.readObject();
        in.close();
    } catch (IOException ex){
        ex.printStackTrace();
    } catch (ClassNotFoundException ex){
        ex.printStackTrace();
    }  

    Kontoverwaltung kontover = new Kontoverwaltung(kontoliste); 
    kontover.starten();//Starte Kontoverwaltung.

thank you.

Eclipse reads the file from the working directory of the launched program. By default, Eclipse sets the working copy to the path of the project's root directory (typically the directory that contains the src directory).

You can change the working directory from the Run Configurations dialog under the Arguments section.

您可以写下konto.txt文件的完整路径,例如,类似“ c:\\ test \\ konto.txt”的文件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM