开发者

What are the best/simplest classes used for WRITING files in Java?

开发者 https://www.devze.com 2023-02-09 00:15 出处:网络
Was anything introduced in Java, in the last editions (1.5/1.6) that facilitate writing strings开发者_开发百科 to files (the Scanner of writing)?Easier than FileWriter?It\'s not a core library in Java

Was anything introduced in Java, in the last editions (1.5/1.6) that facilitate writing strings开发者_开发百科 to files (the Scanner of writing)?


Easier than FileWriter?


It's not a core library in Java but FileUtils in Apache Common IO is a useful class.

FileUtils.writeStringToFile(File file, String data );


I tend to use PrintStream and printf.


I don't think so, I don't imagine what the "Scanner for writing" would be - I don't see a duality there. For simple writing of text, a Writer seems enough.

If you are thinking of something like a formatter, there are good third party libraries, for example, I like Freemarker.


I find I use RandomAccessFile a lot.

RandomAccessFile rafWrite = new RandomAccessFile("<file name>", "<mode, usually rw>");
rafWrite.writeBytes("<text you want to write>");
0

精彩评论

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