Im new to java. I Created this code to get a better grasp and idea how files works. The code executes but the file never appears on my desktop, can someone tell me why and how i can correct this issue.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class CreateFile1{
    public static void main(String[] args) throws IOException{
    File f = new File("C:/Users/Solris/Desktop");
    

BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write("Testing");
output.close();
}
}

You deliberately ignore any IOException, which is dumb, really dumb. Your file isn't getting written, and you chose not to display any error messages that Java may have about it? Get rid of the throws clause. Put your code in a try/catch block, and print out any exceptions that get thrown.
Exceptions are there to HELP you.
ps Desktop is a directory, not a file.

Because: "C:/Users/Solris/Desktop" is NOT a file. It is a Directory.
Shouldn't you do something like this: File f = new File("C:/Users/Solris/Desktop/file.txt");

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.