ImageIO class.Here is the code snippent I wrote:
/* Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
// save captured image to jpg file
ImageIO.write(image, "jpg", new File(outFileName));*/
And here is the exception I am finding (I never found this before, I
runned the code thousands times before)
/*java.io.FileNotFoundException: pic5.jpg (Access is denied)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
at
javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:44)
at
com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)
at
javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:391)
at javax.imageio.ImageIO.write(ImageIO.java:1483)
at Test_ScreenShot.main(Test_ScreenShot.java:112)
at Test_Main.main(Test_Main.java:466)
at Test_ScreenShot.main(Test_ScreenShot.java:129)
Press any key to continue...*/
When I googled I found the following informations:-
1)from sun's bug database:-
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6247985
2)from SUN Developer Forums
http://forum.java.sun.com/thread.jspa?threadID=768917&messageID=4382833
3)from Java.NET forum(here they r getting the bug while they r using
createScreenCapture() method of robot class,I am
also using that in my code)
http://forums.java.net/jive/thread.jspa?messageID=123247
4)from SUN's archieve
http://archives.java.sun.com/cgi-bin/wa?A2=ind0207&L=java-imageio-interest&D=0&P=1483
5)Here is the actual implemetation of ImageIO class.I'm getting error
at 391 no. line.
http://kickjava.com/src/javax/imageio/ImageIO.java.htm
============================================================================================
Now I tried the following alterntive form jdk 1.2
to read:-
FileInputStream fis = new FileInputStream(file);
JPEGImageDecoder jpeg = JPEGCodec.createJPEGDecoder(fis);
jpeg.decodeAsBufferedImage();
fis.close();
But after running a long time suddenly its giving exception:-
Exception in thread "main"
com.sun.image.codec.jpeg.ImageFormatException: Not a JPEG file: starts
with 0xff 0xd9
at
sun.awt.image.codec.JPEGImageDecoderImpl.readJPEGStream(Native Method)
at
sun.awt.image.codec.JPEGImageDecoderImpl.decodeAsBufferedImage(Unknown
Source)
============================================================================================
My question is:-
What is the way to read and write image in JDK?Is there any bug free
way?what is it?
Thanks And Regards
Subhadip
The links suggested this error should actually be a
SecurityAccessException or similar, which suggests
this code might be run from within a security sandbox
that does not allow file writing (and is not 'trusted').
Is the snippet you posted being run from the command line?
In an applet? An application launched using web start?
Andrew T.
Please refrain from multi-posting in future.
(X-post to c.l.j.h./c.l.j.p./s.i.p., w/ f-u to c.l.j.h. only)
Andrew T.