我写了一个日志文件到我的 sd(三星 Galaxy Nexus 的内部存储)。实际上,该文件在 Windows 中是不可见的。如何让用户访问它们?
this.state = Environment.getExternalStorageState();
返回“已安装”
这是我的代码:
/**
* Creates a new instance of Logger
*
* */
public Logger() {
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath();
this.file = new File(path, "log.txt");
}
/**
* Writes results to log file
*
* **/
public void log(boolean isConnected, int signalStrength) {
try {
this.buf = new BufferedWriter(new FileWriter(this.file, true));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Calendar time = Calendar.getInstance();
String result = time.getTime().toString() + " "
+ String.valueOf(isConnected) + " "
+ String.valueOf(signalStrength);
this.buf.write(result);
this.buf.flush();
this.buf.close();
} catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}
它不会写任何东西(即使我没有收到任何异常)。清单包含:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
编辑:
File path = Environment.getExternalStorageDirectory()
.getAbsoluteFile();
没有帮助。