作者brian354 (NING)
看板java
標題[問題] command line 讀取資料
時間Thu Feb 27 03:23:37 2014
想請問各位要如何在command line 中加入資料
程式碼如下:
BufferedReader br_f= new BufferedReader(new InputStreamReader(System.in));
String getfileName = br_f.readLine();
FileReader fr = new FileReader(getfileName);
我在command line 中輸入 java project.java < test.txt 會跑出錯誤訊息如下:
Exception in thread "main" java.io.FileNotFoundException: 4 (No such file
or directory)
但我如果先輸入java project.java enter輸出後 再打test.txt又可以正確執行
想請問是否有方法可以解決
麻煩各位了
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.16.122
1F:→ danny8376:你知道command line那行是直接把test.txt的內容當你打的 02/27 03:25
2F:→ brian354:了解!那想請問該如何直接以“<”方式來input 值 02/27 03:34
3F:推 bleed1979:你可以用main method的參數args 02/27 08:18
4F:→ brian354:有試著用過args,可是使用“<”不是存在args裡 02/27 08:46
5F:→ tkcn:你沒搞懂 1F 說的 02/27 10:24
6F:→ Aztecs:為什麼要加.java?? 02/27 11:41