我写了一个日志文件到我的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();
没有帮助。
答案 0 :(得分:1)
该文件存在,但尚未被MediaScanner接收。你可以通过打开一个shell来验证:
adb shell ls -l /mnt/sdcard/clown.txt
您需要等待它被拾取,重新启动或(最好),在您写完文件后调用MediaScannerConnection.scanFile()。