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?

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.