Reputation: 6774
I have a java program which searches for files in a directory and returns names matching Test______.java, but i would want to find the package name for each of these java files.How can i do this?
Upvotes: 1
Views: 173
Reputation: 3021
It sounds like you're not actually loading these files into your current JVM class loader? If you are, you can use introspection.
If not, you'll need to open the files using a FileInputStream, then use a BufferedInputStreamReader to read the file line by line and search for the package statement.
Upvotes: 0
Reputation: 308733
The easiest way is to open each file and parse out the package com.foo.bar
statement, wherever you find it.
Upvotes: 2