Suresh S
Suresh S

Reputation: 17

How to create a file in java without a extension

Is it possible in java to create a file without extension

Upvotes: 2

Views: 3991

Answers (2)

Chad Okere
Chad Okere

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

Adriaan Stander
Adriaan Stander

Reputation: 166396

You can try

File f;
f=new File("myfile");
if(!f.exists()){
  f.createNewFile();
}

Upvotes: 10

Related Questions