Reputation: 17
Is it possible in java to create a file without extension
Upvotes: 2
Views: 3991
Reputation: 4578
Yes, it's easy. No different then doing it with an extension. So for example, if you have a string you want to write to a file, you can do
FileOutputStream out = new FileOutputStream("noExtension");
PrintStream printout = new PrintStream(out);
printout.println("Hello world!");
printout.close();
You could skip the PrintStream and do out.write("Hello world!".getBytes());
if you wanted.
Upvotes: 1
Reputation: 166396
You can try
File f;
f=new File("myfile");
if(!f.exists()){
f.createNewFile();
}
Upvotes: 10