开发者

Different ways of creating files

开发者 https://www.devze.com 2023-02-22 16:51 出处:网络
There are methods for creating files in java.io.File (like createNewFile() or mkdir()). Are there other ways of creating files in Java SE using \"st开发者_Go百科andard\" API? When you create a FileOup

There are methods for creating files in java.io.File (like createNewFile() or mkdir()). Are there other ways of creating files in Java SE using "st开发者_Go百科andard" API?


When you create a FileOuputStream, the file is created, if it does not exist, although this is not guaranteed:

A file output stream is an output stream for writing data to a File or to a FileDescriptor. Whether or not a file is available or may be created depends upon the underlying platform.


FileOutputStream can be used to create a file as shown below

FileOutputStream fos = new  FileOutputStream("myfile");
FileOutputStream fos = new FileOutputStream(new File("myfile"));


You can use PrintWriter in conjunction with FileWriter such as PrintWriter write = new PrintWriter(new FileWriter("FileName", false)); writing to blank file or BufferedWriter works with FileWriter as well, such as BufferedWriter writer = new BufferedWriter(new FileWriter("FileName"));

0

精彩评论

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

关注公众号