Results 1 to 4 of 4
  1. #1
    yande is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Unhappy File copying and time stamp extraction(java)

    I am new with java and i need help on code that will

    Use classes such as swing and any of your own to

    1*copy Files from one Folder to another

    Eg E:\POSTUP\FULL TO E;\POSTUP

    2*The copied files should have thier time-stamps extracted ,sorted
    and stored in an appropriate Data structure

    3*Create a folder based on the largest time stamp with the name set to this time stamp

    4*Please the copied files into the newly created folder

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,842
    Rep Power
    19

    Default

    What have you tried so far then?
    What errors are you getting?

  3. #3
    yande is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    this is wat i have tried

    Java Code:
    import java.io.*;
    
    public class CopyFile
    {
      private static void copyfile(String srFile, String dtFile){
        try{
          File f1 = new File(srFile);
          File f2 = new File(dtFile);
          InputStream in = new FileInputStream(f1);
          
          //For Append the file.
    //      OutputStream out = new FileOutputStream(f2,true);
    
          //For Overwrite the file.
          OutputStream out = new FileOutputStream(f2);
    
          byte[] buf = new byte[1024];
          int len;
          while ((len = in.read(buf)) > 0){
            out.write(buf, 0, len);
          }
          in.close();
          out.close();
          System.out.println("File copied.");
        }
        catch(FileNotFoundException ex){
          System.out.println(ex.getMessage() + " in the specified directory.");
          System.exit(0);
        }
        catch(IOException e){
          System.out.println(e.getMessage());      
        }
      }
      public static void main(String[] args){
        switch(args.length){
          case 0: System.out.println("File has not mentioned.");
              System.exit(0);
          case 1: System.out.println("Destination file has not mentioned.");
              System.exit(0);
          case 2: copyfile(args[0],args[1]);
              System.exit(0);
          default : System.out.println("Multiple files are not allow.");
                System.exit(0);
        }
      }
    }
    Last edited by JosAH; 05-31-2011 at 06:42 PM. Reason: added [code] ... [/code] tags

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,842
    Rep Power
    19

Similar Threads

  1. File Extraction using Java
    By yap_1991 in forum Advanced Java
    Replies: 7
    Last Post: 05-14-2010, 08:06 AM
  2. Time zone stamp
    By ddscart in forum New To Java
    Replies: 1
    Last Post: 08-02-2009, 08:41 PM
  3. Creating Folder in JAVA and Copying File
    By fnoman in forum New To Java
    Replies: 8
    Last Post: 10-18-2008, 07:33 AM
  4. Replies: 1
    Last Post: 02-04-2008, 08:26 PM
  5. Replies: 13
    Last Post: 01-09-2008, 06:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •