将项目从Netbeans导入Eclipse,.txt文件除外



我在Netbeans中做了一个项目,并将其归档为.zip。然后,在Eclipse中导入它后,它找不到我读取的特定txt文件。我试着把它放在项目中的任何地方,每个文件夹中,但它仍然找不到。我刷新了项目页面。

    public static void Muser() throws FileNotFoundException, IOException, NoSuchAlgorithmException {// lista user 
    int nr = 0;
    FileInputStream fstream = null;
    fstream = new FileInputStream("user.txt");
    // use DataInputStream to read binary NOT text
    // DataInputStream f = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
    String cerere = br.readLine();
    while (cerere != null) {
        m.linie++;
        U user;
        String[] date = cerere.split(" ");
        Key cheie = KeyGenerator.getInstance("DESede").generateKey();
        sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
        String stringCheie = encoder.encode(cheie.getEncoded());
        System.out.println(date[0] + " KUT: " + stringCheie);
        user = new U(date[0], cheie, Integer.parseInt(date[1]), Integer.parseInt(date[2]));
        m.adaugaU(date[0]);
        userList.add(user);
        cerere = br.readLine();
    }
}

它给了我以下错误

Exception in thread "main" java.io.FileNotFoundException: user.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at server.Server.Muser(Server.java:319)
at server.Server.main(Server.java:345)

我解决了,这是一个路径问题。

"我在项目中到处都包含了文件,但它仍然找不到"

如果您使用这个"user.txt"相对路径,在Eclipse中,该文件应该直接放在项目根中

ProjectRoot
          user.txt
          src
          bin

相关内容

  • 没有找到相关文章

最新更新