• Post Reply Bookmark Topic Watch Topic
  • New Topic

Directory and File copying in Linux using Java  RSS feed

 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

Kindly share the Java code for the following

1. Java code to create a directory in Linux
2. Java code to copy files from one location to another in Linux

Thanks,
Faraz
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faraz Ka wrote:
1. Java code to create a directory in Linux


Have you taken a look at the java.io.File class?


Faraz Ka wrote:
2. Java code to copy files from one location to another in Linux


Have you taken a look at the java.io.FileInputStream and java.io.FileOutputStream classes?

Henry
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and the Java Tutorials section?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:Have you taken a look at the java.io.File class?

Have you taken a look at the java.io.FileInputStream and java.io.FileOutputStream classes?


But nowadays you don't need to use those low-level file-access objects to copy a file. In Java 7, the java.nio.file.Files class has a group of static methods called "copy" which take care of all the ugly details for you. Also in the java.nio.file package is DirectoryStream which allows you to iterate over the files in a directory. The API documentation for DirectoryStream has an example of how to do that. What I'm saying is that the methods you were thinking of are now obsolete and you can do the same thing in a lot fewer lines of code.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faraz Ka wrote:...Kindly share the Java code for the following ...

Don't ask for code. Try the programs yourself and post if you get stuck with your code.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, take a look at Commons-IO. It provides good helper method for things like copying a directory recursively.
.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!