【发布时间】:2015-09-24 11:33:16
【问题描述】:
我正在使用此代码存储一个文本文件,其中包含按下应用程序中的“开始”按钮并进一步阅读它的时间名称。我正在尝试将文件保存在用户安装应用程序的内存中(即 SD 卡或手机内存)。我正在存储的文件可以很好地读取并显示在 logcat 中,但我找不到它保存在内存中的位置(电话或 SD)。
public void write_data(String s, Queue<SeismicDataPoint> t) throws IOException {
String path = getBaseContext().getFilesDir().getAbsolutePath();
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
FileOutputStream fOut = getBaseContext().openFileOutput(s + ".txt", MODE_APPEND);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
SeismicDataPoint temp ;
for(int i = 0; i < bufferSize; i++)
{
temp=t.poll();
osw.append(temp.timestamp+" "+temp.x+" "+temp.y+" "+temp.z+"\n");
}
osw.flush();
osw.close();
}
public void read_data(String s) throws IOException {
BufferedReader b = new BufferedReader(new FileReader(s+".txt"));
while(true){
String osw = b.readLine();
if(osw==null)break;
}
这里也是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.falldetect" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
【问题讨论】: