Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

copying zip files  RSS feed

 
grigoris philippoussis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I'm having problems copying zip files. I have a piece of code that looks like this:

<code>

public static void copyFiles(String source, String target) throws IOException{

File inputFile = new File(source);
File outputFile = new File(target);

FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;

while ((c = in.read()) != -1)
out.write(c);

in.close();
out.close();
}

</code>

..which works fine when copying .xml files, but sometimes it needs to cope with .zip files too. What happens is that the .zip is copied, but it's contents are corrupted somehow.

Does anyone know how to re-write this so that it can cope with zips?

Thanks.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't use Readers and Writers; those are for text files. For binary files -like ZIP- you need to use streams (the FileInputStream and FileOutputStream classes).
 
grigoris philippoussis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, I'll give that a try
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!