Hello

Consider this scenario:

File file;

and later

file = new File("Hello.txt");
file = new File("hi.txt");

As you all know, this will create two text files in java. How do I delete one of these files, as in if I only wanted to delete hi.txt?

Recommended Answers

No they don't. Those files won't actually be created until you open a FileWriter, FileOutputStream, etc, with them. "new File(String)" does not physically create a file on the file system.

Jump to Post

All 2 Replies

No they don't. Those files won't actually be created until you open a FileWriter, FileOutputStream, etc, with them. "new File(String)" does not physically create a file on the file system.

But if those files already exist, you can look at the java.io.File API. There you will find what you need. Always look the API.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.