Reputation: 1164
I have to create the installer with runnable jar file ,when the jar file will run it has to copy the files on some directories. I have included few folders in the java project as in the below image :
I have to paste dcc, contactless and vfsc5000 folder on to certain directories.
I am using this piece of code :
public class copyFiles {
// private static final String MAIN_PATH = "C:\\Users\\Hamza\\Documents\\";
private static final String MAIN_PATH = "resources";
public static void main(String[] args) throws IOException {
// file1: "Hello World!"
FileUtils.copyDirectory(FileUtils.getFile(MAIN_PATH), // source
FileUtils.getFile("C:\\Windows\\java\\classes\\postilion" + "contactlessVfsc5000\\")); // destination
}
}
But when I export runnable jar and execute it in the cmd, it throws File not found exception, Source "resources does not exist". It means the jar is not exporting those folders. Please help me solve this .Thanks.
Upvotes: 1
Views: 1440
Reputation: 375
you have to add the required folder to the build path using following step:
click project -> properties -> Build Path -> Source -> Add Folder
and then use class.getResourceAsStream() to read it instead of File and FileReader.
Hope it works !! :)
Upvotes: 1