Nitin Kumar Nitin Kumar - 3 months ago 18
Java Question

How can I run a bat file which is in my Project's package, Without using the full path

I wanted to know that how can I run a bat file of my Project's package, Without using the full path as for different Computers the file path will be different.

not like this:


Instead something like we use in getResource() method. That is:


Simply the package name and the file name. I tried with this type of filepath but got error saying file not exists.

I want to know because in every computer that path will get changed (username, drive etc. or may be file will not be present there)

So how can I use the Bat file that is in my package, instead of a full path with drive name, username and all.


To run multiple commands in one cmd command, you can see the answer on this question.

To get the output, you can use this :

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ( (line = reader.readLine()) != null) {
String result = builder.toString();