Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

copying files from one folder to another  RSS feed

 
jasdeep parmar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to jpeg images from one file to another. I was using the the BuffereImage and Image writer to get the images and write to another folder. I have large volume of files to write (more than 20000).
I am using ImageWriter.dispose()after writing each image and making all inputStreams to null and calling System.gc but I still get java.lang.out.ofmemory exception heap space after about 6000 files.
Can anyone please suggest if there is another way I can implement this functionality.
This the code that I am using to write the files
file = new File(name);

input = ImageIO.read(file);

Iterator iter = ImageIO.getImageWritersByFormatName("JPG");
if (iter.hasNext()) {
ImageWriter writer = (ImageWriter)iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
float values[] = iwp.getCompressionQualityValues();
//set compressionQuality
iwp.setCompressionQuality(55/100);
if (!newName.endsWith(".jpg")) {
newName += ".jpg";
}
File outFile = new File(destinationLoc+newName);
System.out.println("THE NEW NAME " + newName + " OUTFILE "+ outFile);
FileImageOutputStream output =
new FileImageOutputStream(outFile);
writer.setOutput(output);
IIOImage image = new IIOImage(input, null, null);
System.out.println( "Writing " + 75 + "%");
writer.write(null, image, iwp);

writer.dispose();
input=null;
output=null;
writer=null;
System.gc();

thanks
[ October 08, 2008: Message edited by: jasdeep parmar ]
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just need to copy them as they are you don't need to treat them as images. Instead, you can use regular file reading / writing (using InputStream and OutputStream), or file channels:
 
jasdeep parmar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had tried that way earlier but I get this
but i get this error
Exception in thread "main" java.lang.UnsatisfiedLinkError: inode0
at sun.nio.ch.FileChannelImpl.inode0(Native Method)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:868)
at sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:443)
at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:516)

I tried look to up but not able to understand this error or how to fix it.
thank you
[ October 08, 2008: Message edited by: jasdeep parmar ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a "my Java installation is broken" error.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!