1)一定要在你的清单中有这个:
2)无论是使用仿真器还是使用设备进行测试都会产生影响.如果是后者,请务必从PC上卸下设备(选择:“仅充电”).调试仍然会以这种方式工作.只是你不能同时写作和观看.
此方法有效:
public void writeToExternalStoragePublic(String filename, int content) {
String packageName = this.getPackageName();
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/Android/data/" + packageName + "/files/";
if (isExternalStorageAvailable() && !isExternalStorageReadOnly()) {
try {
boolean exists = (new File(path)).exists();
if (!exists) {
new File(path).mkdirs();
}
// Open output stream
FileOutputStream fOut = new FileOutputStream(path + filename,true);
// write integers as separated ascii's
fOut.write((Integer.valueOf(content).toString() + " ").getBytes());
fOut.write((Integer.valueOf(content).toString() + " ").getBytes());
// Close output stream
fOut.flush();
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}