Hi I have a java eclipse project which I want to execute from command line. I made a jar of it and am running it from command line.
I figured out how to access a file in a Jar by using getresourceasstream.
Ex:
InputStream is = Extractor.class.getResourceAsStream("CompanyNameListModified.txt");
BufferedReader in=new BufferedReader(new InputStreamReader(is));`
What I wanna know now is how to access a directory from jar .
Currently:
Runtime.getRuntime().exec("hadoop fs -get /tmp/stockmarkets/ localfile");
File dir = new File("/home/hadoop/project/localfile");`
This gives a filenotfoundexception.
What I want to do is
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
....
}
}
Hence goto the directory and loop over each file in that directory.. How should I do it so it works for my JAR.?
So I tried this:
Runtime.getRuntime().exec("hadoop fs -get /tmp/stockmarkets/ localfile");
File dir =new File(Extractor.class.getResource("/home/hadoop/project/localfile").getPath());
error:
Exception in thread "main" java.lang.NullPointerException
I checked my directory it does have the local file directory.