我創(chuàng)建了一個(gè) android 文件選擇器,它返回文本文件的 uri。我想打開并讀取文件并存儲(chǔ)它的數(shù)據(jù)。我的代碼是:private void covertFile(Uri data) { InputStream inputStream = getContentResolver().openInputStream(data); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); String myText = ""; int in; try { in = inputStream.read(); while (in != -1) { byteArrayOutputStream.write(in); in = inputStream.read(); } inputStream.close(); myText = byteArrayOutputStream.toString(); }catch (IOException e) { e.printStackTrace(); } myTextView.setText(myText); }但這條線InputStream inputStream = getContentResolver().openInputStream(data);給出了java.Io.FileNotFoundException. 我該如何解決這個(gè)問(wèn)題?
1 回答

繁華開滿天機(jī)
TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
首先創(chuàng)建文件對(duì)象
String path = data.toString(); File file = new File(path);
現(xiàn)在將文件對(duì)象作為 arg 傳遞到 InputStream 中
InputStream inputStream = getContentResolver().openInputStream(file);
添加回答
舉報(bào)
0/150
提交
取消