开发者

How to create a file in java without a extension

Is it pos开发者_开发知识库sible in java to create a file without extension


You can try

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜