使用Java搜索文件内容? [英] Searching a Files Content Using Java?

查看:106
本文介绍了使用Java搜索文件内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用java编写一个应用程序,它允许我打开文件(txt)并使用用户输入,搜索特定单词或字符串的所有实例。



由于这里可能会有更多经验丰富的程序员,所以我想就如何创建这样的工具提供一些建议。如何创建一个基本的文本搜索工具?



我一直在玩一些java类,如File,FileOutputStream,FileInputStream,InputStreamReader,OutputStreamReader,FileReader, StreamTokenizer,并想知道使用java打开和搜索文件的最佳方式?



感谢您的任何输入,
Des。

解决方案使用文件扫描仪和一个 StringBuilder 应该给你一个很好的开始。


I would like to write an application, in java, that allows me to open a file (txt) and using the users input, search for all instances of a particular word or string.

As there are probably more experienced programmers here, i would like some advice about how to go about creating such a tool. How would you go about creating a basic text search tool?

I have been playing around with some java classes such as File, FileOutputStream, FileInputStream, InputStreamReader, OutputStreamReader, FileReader, StreamTokenizer and would like to know the optimal way to open and search a file using java?

Thanks for any input you may have, Des.

解决方案

Using a File with a Scanner, and a StringBuilder should give you a good start into that topic.

这篇关于使用Java搜索文件内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆