Reputation: 1
This sample is supposed to locate the copied over .zip file from the build output directory but for some reason it doesn't find that file. I created a resource directory in the root directory and marked it as "Resource Root" and still didn't work. Any help is appreciated. Here is a snippet of the code:
if (install && package == null) {
File file = new File("file.zip");
byte[] bytes = new byte[(int) file.length()];
try {
FileInputStream inputStream = new FileInputStream(file);
inputStream.read(bytes);
inputStream.close();
}
catch (FileNotFoundException ex) {
System.out.println("File Not Found.");
return;
}
catch (IOException ex) {
System.out.println("Error Reading The File.");
ex.printStackTrace();
}
Here is a screenshot of the project structure: Project Structure
Upvotes: 0
Views: 78
Reputation: 919
I suppose you mean you've created the file in the /main/resources
folder of your project?
If that's so, then you can copy it as such:
public static void main(String[] args) throws IOException {
var path = Main.class.getResourceAsStream("/myfile.txt");
Files.copy(path, Path.of("file.txt"));
}
Upvotes: 1