我需要從目錄 Tsks 中的檔案中獲取文本。每個檔案都有名稱“任務” 類(1或2) 規范中的隨機符號[]我試圖打開檔案
\\app\\src\\main\\res\\Tasks\\
我不能這樣做。下面是我的代碼。
public class Task1 extends AppCompatActivity {
final Random random = new Random();
public String specifications[] = new String\[\]{"1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e" , "f"};
public String[] linii = new String[5];
public void main(String[] args) throws IOException {
Bundle arguments = getIntent().getExtras();
int clasik = arguments.getInt("class") - 2131230843;
FileInputStream fstream = new FileInputStream("D:\\Project\\Proektorat\\app\\src\\main\\res\\Tasks\\tasks" clasik specifications[random.nextInt(15)] ".txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
int i = 0;
while ((br.readLine()) != null){
linii[i] = br.readLine();
i = 1;
}
和錯誤:
W/System.err: java.io.FileNotFoundException: D:\\Project\\Proektorat\\app\\src\\main\\res\\Tasks\\tasks1a.txt: open failed: ENOENT (No such file or directory)
W/System.err: at libcore.io.IoBridge.open(IoBridge.java:574)
W/System.err: at java.io.FileInputStream.\<init\>(FileInputStream.java:160)
W/System.err: at java.io.FileInputStream.\<init\>(FileInputStream.java:115)
W/System.err: at com.example.project.Task1.main(Task1.java:26)
W/System.err: at com.example.project.Task1.onCreate(Task1.java:41)
W/System.err: at android.app.Activity.performCreate(Activity.java:8290)
W/System.err: at android.app.Activity.performCreate(Activity.java:8269)
uj5u.com熱心網友回復:
您正在訪問您的計算機資源,這是您的手機/模擬器無法訪問的。
查看此介紹,了解如何使用資源。您可能會對訪問原始檔案部分特別感興趣。
或者,您可以使用手機/模擬器的檔案系統并使用設備檔案資源管理器上傳檔案(這是一個 Linux 系統,以防您不熟悉)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/534569.html
標籤:爪哇安卓
