Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File copying  RSS feed

 
Nijin puthiya purayil
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...
 
Rob Spoor
Sheriff
Posts: 20968
84
Chrome Eclipse IDE Java 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: 20968
84
Chrome Eclipse IDE Java 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...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!