Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

File copying

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
I have two files in my temp directory...i want to copy these two files to another file in the same directory...is it possible by using FileInputStream() and FileOutputStream()??? I'm confused in using the for loop...
where can i use the for loop??Below is my code snippet
Please do help me...
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your copying code itself is correct with one exception - 0 is a valid return valid for read; you should check for >= 0, > -1 or != -1 instead of > 0.
Now all you need to do is call that code twice. That means that you should put the copying code in a separate method; in fact, several libraries have utility methods for that.
 
Nijin puthiya purayil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,
But now i can find only one file in my destination file...i did as you said...i replaced >0 to != -1 and placed the copying method separately...
can there be any problem with the extension of the file??here the extension for both source and destination files are .deb....
 
Rob Spoor
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you calling the copy code now, for both files?
 
Nijin puthiya purayil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm not passing any arguments here...do i have to pass??
i'm calling the method after the OutputStream os = new FileOutputStream(file2,true);...and placed the while loop inside that method...
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!