JAVA 一問: 點樣可以用cmd 一次過 run program 同開埋果txt file呀!! thx......

2007-03-20 10:51 am
我想咁樣行cmd 黎run java 開txt file,

C:\\> java TextFileReader myTEXT.txt

應該點寫,睇左好多網都唔明>thx
更新1:

唔明....thx

更新2:

有冇d簡單sample呢 我唔明 [] args 同args[0] 請指導

更新3:

我想行cmd java ReadTextFile 可以一次過拎埋個filename Sample: C:\> java ReadTextFile myText.txt 可以幫下我嗎??

回答 (2)

2007-03-21 9:30 am
✔ 最佳答案
public static void main( String[] args )
{
// if you type "java TextFileReader yourText.txt" in the command line
// then "yourText.txt" is stored into the variable fileName as a string
String fileName = args[0];

// do something to open the text file
// where the file name is stored in the variable fileName
//...
}
2007-03-20 7:03 pm
閣下可以用args陣列便可以在main()內找出輸入的第1個,
(即args[0])


收錄日期: 2021-05-03 05:45:26
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070320000051KK00363

檢視 Wayback Machine 備份