kav*_*vie 6 android findbugs character-encoding spotbugs
我正在使用 FileWrite 类写入文件。它工作正常。但 FindBugs 指出了我的代码片段中的一个小问题。
代码片段:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd");
Date now = new Date();
String fileName = formatter.format(now) + ".txt";
FileWriter writer = null;
try {
File root = new File(Environment.getExternalStorageDirectory(), "Test");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, fileName);
writer = new FileWriter(gpxfile, true);
writer.append(text + "\n\n");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
查找错误报告:
依赖默认编码 发现依赖默认编码: new java.io.FileWriter(File, boolean)
我在哪一行收到此错误?
writer = new FileWriter(gpxfile, true);
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我这到底是什么吗?我们该如何解决这个问题?
通过替换解决了这个问题
FileWriter writer = new FileWriter(gpxfile, true);
Run Code Online (Sandbox Code Playgroud)
和
FileOutputStream fileStream = new FileOutputStream(gpxfile);
writer = new OutputStreamWriter(fileStream, "UTF-8");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9366 次 |
| 最近记录: |