• Post Reply Bookmark Topic Watch Topic
  • New Topic

Directory and File copying in Linux using Java  RSS feed

 
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
 
author
Marshal
Posts: 23435
138
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
 
Marshal
Posts: 58295
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and the Java Tutorials section?
 
Sheriff
Posts: 23451
46
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.
 
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.
 
author & internet detective
Sheriff
Posts: 38014
603
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.
.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!