Reputation: 961
I'm giving input image to File for some purpose I stored Image and source file in same package but why I'm getting this error please help me ...
my package is xyz
and source file name image.java
and image is stored in xyz/original.png
(i.e. Image path), below is code snip of image.java...
File file = new File("original.png");
try {
FileInputStream imageInFile = new FileInputStream(file);
byte imageData[] = new byte[(int)file.length()];
imageInFile.read(imageData);
}
Upvotes: 2
Views: 3935
Reputation: 961
After searching a lot on stack overflow sites I found the solution and that is I placed my image may be in wrong directory :( using
String file_name = "original.png";
File file = new File(file_name);
System.out.println(file.getCanonicalPath());
I printed canonical path and this shows me that my image must be inside that path, After copying image at that path my code executed... thank you for your cooperation in resolving my problem.
Upvotes: 0
Reputation: 2989
InputStream input = classname.class.getResourceAsStream("IMAGE FILE");
try using above approach to load the file . just pass the file name if its in the same package.
Upvotes: 1