2010-10-01 43 views
0

我需要掃描輸入文件並搜索特定值。我怎麼做?如何掃描文件以搜索值

+1

什麼LANGUAG è? (也許你可以使用grep)(呃,我討厭它沒有發佈後的15秒限制,因爲它太短了)。 – tster 2010-10-01 19:11:28

+0

輸入文件數據是什麼樣的?你試過了什麼代碼? – 2010-10-01 19:22:01

回答

2

您可以在File上打開Scanner,使用Scanner.findWithinHorizon()您可以搜索下一次您的研究。

例如:

File file = new File("/Users/me/file.txt"); 
Scanner scanner = new Scanner(file); 
String foundString = scanner.findWithinHorizon("hello", 0); //You can replace Hello with a regex if you want. 

資源: