×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Help needed in copy paste

    I want to copy paste a file from j2me by using file connection. I am successful in copy paste but it is very very slow. I have seen file managers in java copy very very fast. So can any body modify my code to make it much more faster. Code of the main part where the copy paste takes place:
    public void copyFile(String copyPath,String pastePath)
    {
    try
    {
    FileConnection fc1 = (FileConnection)Connector.open(copyPath,3);
    FileConnection fc2 = (FileConnection)Connector.open(pastePath,3);
    InputStream is = fc1.openInputStream();
    OutputStream os = fc2.openOutputStream();
    fc2.create("MyFile.mp3");
    int n;
    byte b[] = new byte[200];
    while((n = is.read(b,0,b.length)) != -1)
    {
    os.write(b,0,n);
    }
    os.close();
    is.close();
    fc1.close();
    fc2.close();
    }
    catch(Exception e)
    {
    }
    }
    .
    I have another code which is somewhat like this:
    .
    public void copyFile(String copyPath,String pastePath)
    {
    try
    {
    FileConnection fc1 = (FileConnection)Connector.open(copyPath,3);
    FileConnection fc2 = (FileConnection)Connector.open(pastePath,3);
    InputStream is = fc1.openInputStream();
    OutputStream os = fc2.openOutputStream();
    fc2.create("MyFile.mp3");
    int n;
    while((n = is.read()) != -1)
    {
    os.write((byte)n);
    }
    os.close();
    is.close();
    fc1.close();
    fc2.close();
    }
    catch(Exception e)
    {
    }
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Help needed in copy paste

    Increase the chunk size of bytes you read at a time - make it 1024 from 200 and check the effect on the speed.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: Help needed in copy paste

    No change. Speed is same. Any other code.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: Help needed in copy paste

    1024 still may be too small, you can try increasing it further, like 8192, 16384, perhaps more. Checking 'n' may give some idea if increasing the size has any use.
    Even if the useful "read-size" remains small, you can try collecting the results of multiple read-s, and write them in a single step.

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: Help needed in copy paste

    This works absolutely fine. And what is logic behind the cut function. I thought somewhat like this firstly i will copy the file and then delete the file from the first file connection. Is it correct or any other process can also be there.

Similar Threads

  1. Copy and Paste in WRT?
    By iraqdevil in forum Symbian
    Replies: 3
    Last Post: 2011-01-11, 15:28
  2. S60 5th Ed. (N97) and copy/paste
    By billmair in forum Series 40 & S60 Platform Feedback Archive
    Replies: 2
    Last Post: 2009-07-19, 01:55
  3. copy and paste on E65
    By Sam Vimes in forum Mobile Java General
    Replies: 2
    Last Post: 2008-10-28, 16:52
  4. How to Copy and paste
    By nadym89 in forum Symbian
    Replies: 2
    Last Post: 2008-06-07, 10:39
  5. copy / paste ... in CEikRichTextEditor
    By Jeepy in forum Symbian
    Replies: 1
    Last Post: 2007-01-17, 14:14

Posting Permissions

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