扫描多个文件头
我在某个目录中有一个java程序。我想让它找到与程序位于同一目录中以 .dat
或 .DAT
结尾的所有文件的列表。然后我需要查看每个文件的前几行并解析标题字符串。该程序应返回一个文件名数组,以及每个文件的前三行的数组。我对 IO 很陌生,有人可以帮忙吗?
Example: C:/my_directory/
Files: Program.class,
FOO.DAT (starts with "Lorem\nipsem\n$$0"),
bar.dat (starts with "ipsem\nLorem\n$$0")
Return: ["FOO.DAT","bar.dat"] and ["Lorem\nipsem\n","ipsem\nLorem\n"]
提前致谢!
I have a java program in a certain directory. I would like to make it find a list of all files that end with .dat
or .DAT
in the same directory as the program. Then I need to look at the first couple of lines of each file and parse a title string. The program should return an array of the file names, and an array of the first three lines of each file. I am pretty new to IO stuff, can anyone help?
Example: C:/my_directory/
Files: Program.class,
FOO.DAT (starts with "Lorem\nipsem\n$0"),
bar.dat (starts with "ipsem\nLorem\n$0")
Return: ["FOO.DAT","bar.dat"] and ["Lorem\nipsem\n","ipsem\nLorem\n"]
Thanks in advanced!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下代码片段打印给定目录中具有
.dat
或.DAT
文件扩展名的所有文件。尝试弄清楚如何从文件中读取前三行。这一定是相当简单的The following code snippet prints out all the files that have
.dat
or.DAT
file extensions in a given directory. Try to figure out how you can read first three lines from a file. That must be fairly straightforward