我需要在单个语句中将内容写入文件,例如 FileUtils.writeStringToFile.
由于它已被弃用,有什么替代方法吗?
Raj*_*ora 11
通过阅读本文档,它指出:
Deprecated. 2.5 use writeStringToFile(File, String, Charset) instead
Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
Run Code Online (Sandbox Code Playgroud)
你可以按照这个例子:
final File file = new File(getTestDirectory(), "file_name.txt");
FileUtils.writeStringToFile(file, "content", "ISO-8859-1");
Run Code Online (Sandbox Code Playgroud)
(String) null如果您不想传递编码,则可以传入您的参数。
欲了解更多信息,您可以通过链接: 使用链接
用这个
File file = ...
String data = ...
try{
FileUtils.writeStringToFile(file, data, Charset.defaultCharset());
}catch(IOException e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11188 次 |
| 最近记录: |