Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: copy files?

  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    copy files?

    Hello,

    I'm trying to copy files from my ipod to a folder on my system.

    using this code:

    PHP Code:
    public class Copy{
        public 
    void copyfile(String origString destthrows IOException{
            
    File fOrig = new File(orig);
            
    File fDest = new File(dest);
            
    FileUtils.copyFile(fOrigfDest);
        }

    when I run the code, only one file is copied with 0 size and gives me an error in the console;


    C:\Documents and Settings\Administrator\My Documents\aaa
    Destination:C:\Documents and Settings\Administrator\My Documents\aaa\Artist - Song.mp3
    source:G:\\iPod_Control\\Music\\F00\\ECLH.mp3
    java.io.IOException: Error performing inpage operation
    at sun.nio.ch.FileDispatcher.pwrite0(Native Method)
    at sun.nio.ch.FileDispatcher.pwrite(Unknown Source)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
    at sun.nio.ch.IOUtil.write(Unknown Source)
    at sun.nio.ch.FileChannelImpl.write(Unknown Source)
    at sun.nio.ch.FileChannelImpl.transferFromFileChannel(Unknown Source)
    at sun.nio.ch.FileChannelImpl.transferFrom(Unknown Source)
    at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:944)
    at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:888)
    at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:835)
    at Lib.Copy.copyfile(Copy.java:13)
    at Lib.Filewalker.walk(Filewalker.java:43)
    at Lib.Filewalker.walk(Filewalker.java:19)
    at Lib.IpodXtract$3.actionPerformed(IpodXtract.java:277)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    any idea what the issue could be?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I hate this error.
    Is this all the code you have? I've seen this error come up when other streams already have the file open. I ask since the FileWalker class looks like it may have something open to the file.

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    I don't think the Filewalker has it open, howeverthe id3 tag reader might, but I thought that wouldn't be an issue since I'm just coping ?

    PHP Code:
        public void walkString path throws IOExceptionTagException {

            
    id3 id3v = new id3();
            
    File root = new Filepath );
            
    File[] list = root.listFiles();
            
    int Counter 0;
            for ( final 
    File f : list ) {
                if ( 
    f.isDirectory() ) {
                    
    walkf.getAbsolutePath() );            } else {
                    
                    
    String Mp3FileName f.getAbsoluteFile().toString();
                    
    String[] tokens Mp3FileName.split("[.]+");
                    
                    
    String Ext tokens[1].toString();
                    if(
    Ext.equals("mp3")){
                        
    Counter++;

                        
    String SongName id3v.getTag(Mp3FileName);
                        if(
    SongName.length() > 0){
                            
    String SourceFile f.getAbsoluteFile().toString();

                            
    System.out.println"Destination:" + Global.DestinationDir "\\" SongName);
                            
    System.out.println"source:" SourceFile.replace("\\""\\\\") );

                            
    Copy cp = new Copy();
                            
    cp.copyfile(SourceFile.replace("\\""\\\\"), Global.DestinationDir "\\" SongName);
                        }
                    }
                }
            }
            
    System.out.println(Counter);
        } 

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No, that's why this is such an annoying error (kinda like a 500 in web world at times; it's a little ambiguous as to what it's doing). The problem is if a file is open with a lock, it will often block anything else from opening it at all including the copy.
    Pulling tags will guarantee that it has opened the file. But I don't know if it has closed it, and without an actual file object to work with it will be difficult to tell for sure what it has done.

    First thing to try, write an overload for the copyfile method that takes two File objects and goes from there. Provide it with f as the source, and create a new file for the destination. See if that works. If not, we'll jump to channel.

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    this is the code for the id3 reader;

    PHP Code:
        public String getTag(String FilePathTempthrows TagExceptionIOException{

            
    //System.out.println(FilePathTemp);

            // Docs: http://javamusictag.sourceforge.net/QuickStart.html
            
            
    File sourceFile = new File(FilePathTemp);
            
    //File sourceFile = ;

            
    MP3File mp3file null;

            try{
                
    mp3file = new MP3File(sourceFile);
            } catch (
    Exception e) {

            }
            
            
    ID3v1 fnt mp3file.getID3v1Tag();
            try{
                
    //System.out.println(fnt.getSongTitle());
                //System.out.println(fnt.getLeadArtist());
                
    String FileName fnt.getLeadArtist() + " - " fnt.getSongTitle() + ".mp3";
                
    //System.out.println("New File Name: " + FileName);
                
    return FileName;
            } catch (
    Exception e) {

            }

            return 
    "";
        } 
    i'm not sure what you mean by writing an overload?

    also in the filewalker code, is there some way to close the id3 class before the filecopy gets executed?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts

    Angry

    Quote Originally Posted by angst View Post
    this is the code for the id3 reader;

    PHP Code:
        public String getTag(String FilePathTempthrows TagExceptionIOException{

            
    //System.out.println(FilePathTemp);

            // Docs: http://javamusictag.sourceforge.net/QuickStart.html
            
            
    File sourceFile = new File(FilePathTemp);
            
    //File sourceFile = ;

            
    MP3File mp3file null;

            try{
                
    mp3file = new MP3File(sourceFile);
            } catch (
    Exception e) {

            }
            
            
    ID3v1 fnt mp3file.getID3v1Tag();
            try{
                
    //System.out.println(fnt.getSongTitle());
                //System.out.println(fnt.getLeadArtist());
                
    String FileName fnt.getLeadArtist() + " - " fnt.getSongTitle() + ".mp3";
                
    //System.out.println("New File Name: " + FileName);
                
    return FileName;
            } catch (
    Exception e) {

            }

            return 
    "";
        } 
    i'm not sure what you mean by writing an overload?

    also in the filewalker code, is there some way to close the id3 class before the filecopy gets executed?
    No, because it doesn't return a ID3v1 object. You can check with that fnt object within that method to see if it has a close mechanism for it.
    For an overload, signature with this: public void copyfile(File src, File dest);


  •  

    Posting Permissions

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