[英]Getting file from sd card to read
只是在獲取文件I / O時有些打h,其中sd中的文件存儲在用戶給定的文件名下。 文件名是通過使用意圖獲得的。 已經四處尋找解決方案,但似乎錯過了一些東西。
任務是,需要到達要讀取文件內容的給定文件名的路徑。 在給定的textview中。文件名是通過意圖獲得的,但File.io似乎仍然無法讀取文件,這給了文件未找到的異常
已經在清單文件中提到了必需的讀寫權限。
簡短示例的任何幫助都將非常有用。 謝謝
public class EmailRead extends Activity {
TextView EtV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.email_read);
EtV = (TextView) findViewById(R.id.Email_Txt);
Intent inn = getIntent();
String Fname = inn.getStringExtra("FileName");
File SdC = Environment.getExternalStorageDirectory();
File file =new File(SdC,SdC.getPath() + "/myDirTab" + "/" + Fname + ".txt");
if (file.exists()) {
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
Log.e("This is for inside", "The Bufferreader");
while ((line = br.readLine()) != null) {
text.append(line);
text.append("/n");
}
} catch (IOException e) {
Log.e("Error in reading line ", "In the catch part of read");
}
EtV.setText(text);
} else {
Log.e("This is for file Exception", "File not found");
}
}
}
在崩潰時,在創建文件時或在緩沖的讀取器中?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.