Is it possible in java to create a file without extension
+10
A:
You can try
File f;
f=new File("myfile");
if(!f.exists()){
f.createNewFile();
}
astander
2010-03-10 07:28:11
will this create file without having extension.
Suresh S
2010-03-10 07:31:21
@SureshS Yes it will. The file created will have exactly the name in quotes - if you add an extension, it will have an extension on disk, otherwise it won't. There is no default extension for the files you create in this manner.
a_m0d
2010-03-10 07:32:39
@Suresh S - it won't if you don't try it! :-)
Stephen C
2010-03-10 07:33:05
@astander thanks i will try @a_mod,stephen C thank u too.
Suresh S
2010-03-10 07:40:08
@Suresh probably worth noting that creating a file without an extension will do nothing different than one created with an exception.
AndyC
2010-03-10 19:21:30
+1
A:
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.
Chad Okere
2010-03-10 07:44:10