Copying complete directory structure using java.io.File

Is there a solution to problem when you want to copy a complete directory structure using java.io.File class as you can copy when using FTP connection.

Is there a solution to problem when you want to copy
a complete directory structure using java.io.File
class as you can copy when using FTP connection.FTP does not have a command to transfer all the files in a directory. FTP clients implement this by invoking single file transfer for each file in a directory.

Similar Messages

  • Trying to copy a directory structure without all of the files.

    Hi,
    Is there a way to copy a directory structure with a number of subdirectories without all of the directory files coming along with it. I thought the cpio command would do that but I can't figure out how to use it.

    CPIO needs a list of files, normally you generate them with 'find', so that would work.
    There's an old thread about this on comp.unix.solaris. Personally, I like my 'rsync' solution. :-) But reading the entire thread may be a good idea.
    http://groups.google.com/group/comp.unix.solaris/browse_thread/thread/e84b458b3ce4b3b8/
    Darren

  • Compressing directory structure using lzma sdk (7z)

    Hi everyone!
    I'm a beginner in things like this, but I need to call some compression method to compress some directory structure. I considered using lzma sdk but I don't have any idea how to do this work with directories. Do I have to copy directory structure and compress files in these directories? How to make one archive file then?
    Oh. I'm using package SevenZip and its main method from LzmaAlone.
    Does anyone knows the idea?
    Thanks in advance...

    lzma sdk is written in java and can be used in java applications. Maybe there is someone who did something like this in the past - called methods from SevenZip package from his own project to compress directory structure, not only single file.

  • File size (using java.io.File)

    Hello all,
    When I want to create an app to be used as file browser, I should like to know the size of a file in a directory. The java.io.File class gives me quite some functionality, but not the functionality to display the file size.
    Does anyone know of a default class that has the functionality to display the file size?
    When no such class exists, I should need to develop it myself. From the top of my head it should be something like this:
    int size = 0;
    int aChar = 0;
    FileReader reader = new FileReader (theFile);
    while (reader.ready() )
        aChar = reader.read()
        size++;
    }The variable size gives me now the number of characters in a file. But this should be done for each file in a particular directory. But does that not ask much CPU performance? Does anyone have an alternative?
    Looking forward to your answer
    Michel

    Hi, I'm having the exact same problem, except that I'm doing a fax system so I can't copy a file while the file is still open. So to check to see if the file is open I have to check the file size in bytes then wait a second and check the file size again. If the file sizes differ then I have to check the next file otherwise I can copy the file. I had a look at the length() method but that will only return the actual length of the file name, not the size of the contents of the file which I need, can anyone please help? Say the file name is 16 ad an a or anything to the file name, if you the call the length() method again it will return 17.

  • Trying to write data to a text file using java.io.File

    I am trying to create a text file and write data to it by using java.io.File and . I am using JDeveloper 10.1.3.2.0. When I try run the program I get a java.lang.NullPointerException error. Here is the snippet of code that I believe is calling the class that's causing the problem:
    String fpath = "/test.html";
    FileOutputStream out = new FileOutputStream(fpath);
    PrintStream pout = new PrintStream(out);
    Do I need to add additional locations for source files or am I doing something wrong? Any suggestions would be appreciated.
    Thank you.

    Hi dhartle,
    May be that can help:
    * Class assuming handling logs and connections to the Oracle database
    * @author Fabre tristan
    * @version 1.0 03/12/07
    public class Log {
        private String fileName;
         * Constructor for the log
        public Log(String name) {
            fileName = name;
         * Write a new line into a log from the line passed as parameter and the system date
         * @param   line    The line to write into the log
        public void lineWriter(String line) {
            try {
                FileWriter f = new FileWriter(fileName, true);
                BufferedWriter bf = new BufferedWriter(f);
                Calendar c = Calendar.getInstance();
                Date now = c.getTime();
                String dateLog =
                    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM,
                                                   Locale.FRANCE).format(now);
                bf.write("[" + dateLog + "] :" + line);
                bf.newLine();
                bf.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
         * Write a new line into a log from the line passed as parameter,
         * an header and the system date
         * @param   header  The header to write into the log
         * @param   info    The line to write into the log
        public void lineWriter(String header, String info) {
            lineWriter(header + " > " + info);
         * Write a new long number as line into a log from the line 
         * passed as parameter, an header and the system date
         * @param   header  The header to write into the log
         * @param   info    The line to write into the log
        public void lineWriter(String header, Long info) {
            lineWriter(header + " > " + info);
         * Enable to create folders needed to correspond with the path proposed
         * @param   location    The path into which writing the log
         * @param   name        The name for the new log
         * @return  Log         Return a new log corresponding to the proposed location
        public static Log myLogCreation(String location, String name) {
            boolean exists = (new File(location)).exists();
            if (!exists) {
                (new File(location)).mkdirs();
            Log myLog = new Log(location + name);
            return myLog;
         * Enable to create the connection to the DB
         * @return  Connection  Return a new connection to the Oracle database
        public static Connection oracleConnectionCreation() throws Exception {
            // Register the Oracle JDBC driver
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            //connecting to the DB
            Connection conn =
                DriverManager.getConnection("jdbc:oracle:thin:@myComputerIP:1521:myDB","user", "password");
            return conn;
         * This main is used for testing purposes
        public static void main(String[] args) {
            Log myLog =
                Log.myLogCreation("c:/Migration Logs/", "Test_LinksToMethod.log");
            String directory = "E:\\Blob\\Enalapril_LC-MS%MS_MS%MS_Solid Phase Extraction_Plasma_Enalaprilat_ERROR_BLOB_test";
            myLog.lineWriter(directory);
            System.out.println(directory);
    [pre]
    This class contained some other functions i've deleted, but i think it still works.
    That enables to create a log (.txt file) that you can fill line by line.
    Each line start by the current system date. This class was used in swing application, but could work in a web app.
    Regards,
    Tif                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Failed to delete a file in MS Vista using java.io.File.delete()

    while trying to delete a file using java.io.File.delete(), it returns true but the file lies intact.
    i'm sure there is no handle or stream open on the file..
    the same code is running fine in XP..
    if anyone can help me.. thanks

    thanks all..
    the problem is diagnosed further..
    MS Vista does not let a user program to delete any file from 'windows' or 'program files' directories..
    Even when the file is deleted manually thru explorer a confirmation is taken from the administrator.. even when he is logged in..
    i for now have opted to install and use my program in Vista outside 'program files' directory...
    more clarification welcome..

  • Add a posixaccount user in posixgroup in sun directory server using java

    Hi
    Anybody now how to add posixaccount user in posixgroup in sun directory server using java code.
    I am able to add normal directory server user in ldap group in java.
    But i am getting any luck to add posixaccount user in posixgroup.
    I know we can set uid value in memberuid attribute but how to add through java program.
    Anybody can paste code for that.
    Thanks.

    To CRabel,
    My company have restriction on using the open sources product/code, but i will take a look on netscape ldap sdk as a reference~
    To raghu1978 ,
    i find a product call Directory Editor 1 2005Q1, I hope it is useful.
    thz all~

  • What should be directory structure for Custom MDS files?

    Hi,
    I have personalize a page and then exported the personalization.
    Now my requirment is to migrate this personalization to other server, for which clients want steps specific to UNIX.
    My doubt is where should I copy these files on the server to import the personalization using XMLImporter command? ( Client do not have JDev on his server, so can not use impot command)
    my custom_top structure is like '/u02/int/applmgr/CUSTOM/xbol/11.5.0'
    The customization is part of product 'OTA'
    I am confused about where to put(Directory structure on custom top) customization and other MDS file to import using XMLImport.
    This customization is also using a Custom LOV for which, I have given the path xbol/oracle/apps/ota/admin/enrollment/webui/XbolGradeRN.
    For now I have transfered the file from window based JDeveloper and things are working fine. I need the UNIX directory structure for MDS files.
    Please help to clear my this doubt.
    Regards,
    Adarsh

    There is nothing specific to UNIX since the files are never picked from the file system on a production instance. You can place them under a temp directory with the proper package structure, the same way you exported personalizations for the seeded pages and the same custom package structure for your new pages and run import command. It's only how you run your import command matters, if you have placed the files in the proper package under some temp directory just give the -rootdir to point to your temp directory and no -rootPackage option.

  • Access mirror site using java, download files and other information?

    Hi, I have 2 nodes/servers on the system both running webservers and having the same interface, but at a time user will access one node at a time from their browser, but this interface will be able to allow the user to get information from the both the nodes. the information that the user can get is DB stored as well as files on the disk of either node.
    i can manage the DB, cuz there is nothing to it, but how do I get files from the other node?
    currently any files/web documents are all stored in a application directory of the web root and protected by htaccess i believe, so when a user logs on to node one he can access all plain text/binary files along with web content since the web server authorizes the user to access anything in that dir. but at the same time from the same session I want to be able to access files in a mirror site using the same username and password and not having him to enter it again. the username/pass combo is replicated on both the servers, it this possible?
    currently i use the http password protection provided by apache to access one node, but can i use the same session on another machine with the same credentials?
    If this is not possible how can i do this programatically using java? can i do can "ls" on the directory i want on another server and display the list to the user and then when he clicks on that file name i fetch it from the backup/mirror server and have him save it using http or ftp?
    It would be great if we can get a solution to this.
    Thank you very much in advance.
    Ankur

    If you install the web server on different machines, It is possible to share the informations between them.

  • Populating MX:Tree with Directory Structure using PHP

    Hello,
    I have written the following php function to return the directory structure :
         public function get_dir_iterative()
              $dir = 'data';
              $exclude = array( 'cgi-bin', '.', '..' );
              $folders = '<?xml version="1.0"?>';
              $folders .= "<node label='Root' path=\"data\">";
              //$folders .= $this->getFolderRecuring("data");
              $exclude = array_flip($exclude);
              $dh = opendir($dir);
              //$stack = array($dh);
              //$level = 0;
                        //closedir(array_shift($stack));
              while(count($stack))
                   if(false !== ( $file = readdir( $stack[0] ) ) )
                        if(!isset($exclude[$file]))
                             if(is_dir($dir . '/' . $file))
                                  $dh = opendir($dir . '/' . $file);
                                  if($dh)
                                       $folders .= "<node label=\"$file\" path=\"$dir/\" isBranch=\"true\" />";
                                       array_unshift($stack, $dh);
                                       ++$level;
                             else
                                  $folders .= "<node label=\"$file\" path=\"$dir/\">";
                   else
                        closedir(array_shift($stack));
                        --$level;
              $folders .= "</node>";
              return $folders;
    When I test this function manually it returns the proper structure.
    But when I call it with help of ZendAMF there is nothing returned and the sandclock is spinning infinite ?!
    here is the flex part:
    private var fms:RemoteObject = new RemoteObject();
    protected function initFileManagerService():void
         fms.destination ='zend';
         fms.source='FileManagerService';
         fms.showBusyCursor=true;
         fms.addEventListener( FaultEvent.FAULT, faultListener);         
         fms.get_dir_iterative.addEventListener( ResultEvent.RESULT, load_result );              
         trace('FileManagerService initialized');
    public function load():void
         fms.get_dir_iterative();
         trace('Service / load');
         private function load_result( e:ResultEvent ):void
              trace('result:'+e.result)                   
    My zend setup is working, any idea what could be wrong ?

    >if you comment out the php and just return "hello" do you get it back in flex?
    Jip, thats working
    >is this line right?>fms.get_dir_iterative.addEventListener( ResultEvent.RESULT, load_result );
    Yes it is correct, thats the way you listen for a result of a specific function when using the zend framework.
    I have other projects running very good like this.
     

  • Change Directory Structure Created in MPZIP file

    I'm trying to standardize my Multisim projects for inclusion in our documentation control system. As I build my project, I have a directory structure that I'm using. When I include the files in the project, the directory structure is remembered in the MPZIP file. However, the default is to unpack all files into the External(Project Name) folder. Following the help, 
    Extracted Path—The location to which the files will be extracted. The default is <project name>External\filename, for example project1External\amplifier.ms12. Use the drop-down lists in the Extracted Path column to select other locations as desired. 
    I can go in and change the directory path of each file using pull-down boxes. This makes  a manual process and if I include datasheets, specifications, and dxf files, is quite time intensive. Is there a way to default to having the project to unpack to the old directory structure? Is there some other way to automate the unpacking? I can manually zip the old project structure, but other than the form of the directories, the MPZIP is so convenient.
    Solved!
    Go to Solution.

    Hi Doug,
    When you unpack the project, the default is to create a new folder and put everything together since it is unlikely that the new computer will have the same file structure as the computer where this project came from.  If you want Multisim to create the same file structure as the original, you can click in the cell under "extracted path" and select the old path, if the folder doesn't exist, Multisim will create one.  Unfortunately, you will have to do this for each item on the table.
    Tien P.
    National Instruments
    Attachments:
    unpack.png ‏17 KB

  • Does migration asst copy entire directory? or just relevant files?

    hello all.
    I'm about to reinstall tiger to a clean drive. I'm wondering that if I use the migration assistant, if it will actually copy over the entire disk? including irrelevant files [orphaned prefs or temporary caches for example], or if it's a cleaner process which only brings the relevant data.
    I guess I'm trying to figure out if it makes more sense just to reinstall everything , the apps, recreate the user folders and bring the library items etc over manually.
    also when it brings everything over, does it just copy the directory? or does it do any optimization +/ defragmenting as it passes over?
    thanks very much everyone.
    s
    G5   Mac OS X (10.4.3)  

    I'm wondering that if I use the migration assistant, if it will actually copy over the entire disk? including irrelevant files [orphaned prefs or temporary caches for example], or if it's a cleaner process which only brings the relevant data.The migration assistant has absolutely no way of knowing about "orphaned prefs" so those will be copied. Temporary caches are not copied.also when it brings everything over, does it just copy the directory? or does it do any optimization +/ defragmenting as it passes over?The copy is not bit wise, so defragmentation does occur as the files are written to the destination hard drive.

  • How use java.io.File ?

    import java.io.File;
    public class test {
         void     help( String[] info ) {
              for ( int x = 0; x < info.length; x++ )
                   System.out.println( info[x] );
         public static void main( String[] args ) {
              test t = new test();
              t.help( args );
              File f = new File("args[0]");
              t.help( f.list() );
    }The File.list() return "String[]", but it no same for "String[] agrs". How to use File.list() ?

    Try doing File f = new File(args[0]);

  • Can It Be Done? - Using Java Class Files from a DB

    Hello,
    I am interested in storing a binary java class file in my oracle DB. Then I want to get it out at runtime and execute methods on it. I am planning on casting the object to an interface and executing the methods within. Please let me know if this is possible and where to look for more info, and a code example would be awesome.
    Joe
    [email protected]

    I think you are going to need to serialize the objects and the classes. (Don't get stuck on semantics here, I don't mean use Java Serialization to write the Class instance, I am referring to writing the .class file to a field in the database.) Obviously the instances are what you are interested in (since you mentioned casting them to interfaces and invoking methods on them), but the class definitions will need to either be available already, or stored elsewhere in the database.

  • Getting a file name using java.io.file

    Dear List,
    I am having problems using java.io package. I am reading a string on a linux tomcat server. I am
    trying to parse a windows type filepath (passed by a web-browser-client) and get only the filename. ie. sample.jpg.
    fileName = "c:\\temp\\sample.jpg"
    java.io.File file = new File(fileName);
    onlyFileName = file.getName();
    remember this on linux, and on my server onlyFileName contains "c:\\temp\\sample.jpg" and not sample.jpg as I would expect.
    can any one tell me what I (yet again) dont understand.? Strangely enough when the server is on windows and I am passing a linux string with the fileseperator as a forward-slash, the code manages to derive the correct filename.
    regards
    Ben

    Post this to the beginners forum - has nothing to do
    with native methods.Apologies I thought Java.io would be "native".
    sorry,
    BB

Maybe you are looking for

  • Exchange commands in VB (PLEASE HELP!)

    Hey everyone, I'm running exchange PowerShell commands from my VB program and I have a quick question. Would it be possible to input my server name where I want to pull the information off of right after it says Get-MailBoxDatabaseCopyStatus. For an

  • Selecting a list of files and creating a list of only the file names?

    Hopefully this is an easy question, one that I can't seem to figure out. I have a folder of photos and I would like to select all their file names and create a text list of just the file names. Every time I try I select the photos themselves and when

  • How to make a block as invisible at SSCRN Output ?

    Hello All,         I have 3 Blocks on my SSCRN and  I have 2 Radio Buttons. I want to make 2 Blocks as Invisible when one of the radio button is selected. Can any one tell me how to do so ? Regards, Deepu.K

  • Connecting 2 RV042 to different subnet and DSL connections

    Small office, 2 RV042, 2 DSL connections. 1 is used striclty for the business side, and the other is for our CCTV network. They also have seperate DSL connections as we have 2 external IP address for clients to connect remotely. We don't want to take

  • Strange request from an e-mail for login details?!

    I received an e-mail today from [email protected] and when I click on the message a dialogue box pops-up asking for a user login and passsword... "To view this page, you need to log in to area "mail.avensc.com" on mail.avensc.com:80." It is then stuc