Azer Rtyu
Azer Rtyu

Reputation: 339

I can't locate files which created by program

I created a desktop project in netbeans, in the project folder I have three files : file.txt, file2.txt and file3.txt, in the load of the program I want to call these three files, and this is the code I tried :

public void run() {

                Path path = Paths.get("file.txt");
                Path path2 = Paths.get("file2.txt");
                Path path3 = Paths.get("file3.txt");

                if(Files.exists(path) && Files.exists(path2) && Files.exists(path3)) {
                    lireFichiers();
                }else{
                    JOptionPane.showConfirmDialog(null, "Files didn't found !");
                }
            }

but when I run my program I get the message : "Files didn't found !" which means he didn't found those files.

those files are created by this code :

File file = new File("Id.txt");
                File file2 = new File("Pass.txt");
                File file3 = new File("Remember.txt");

Upvotes: 0

Views: 68

Answers (4)

Azer Rtyu
Azer Rtyu

Reputation: 339

Thank you all for your help, I just tried this :

File file = new File("Id.txt");
 File file2 = new File("Pass.txt");
 File file3 = new File("Remember.txt");
 if(file.exists() && file2.exists() && file3.exists()){
     // manipulation
 }

and it works

Upvotes: 0

srikanta
srikanta

Reputation: 2999

The following three lines will only create file handlers for your program to use. This will not create a file by itself. If you are using the handler to write it will also create a file for you provided you close correctly after writing.

File file = new File("Id.txt");
File file2 = new File("Pass.txt");
File file3 = new File("Remember.txt");

So, a sample code will look like:

File file = new File("Id.txt");
FileWriter fw = new FileWriter(file);

try
{
   // write to file
}
finally
{
   fw.close();
}

Upvotes: 1

SolessChong
SolessChong

Reputation: 3407

Please specify the language you use.

Generally you could search the file to see whether the files are in the program bootup folder. For webapps you should pay attention to the "absolute path and the relative path".

=========Edit============

If you are using Jave, then the file should be write out using FileWriter.close() before you can find them in your hard disk.

Ref

Upvotes: 0

user1907906
user1907906

Reputation:

If the file is in the root of your project, this should work:

Path path = Paths.get("foo.txt");
System.out.println(Files.exists(path)); // true

Where exatlcy are the files you want to open in your project?

Upvotes: 0

Related Questions