Problem copying a File to another File

My routine to take one File's content and overwrite another File doesn't seem to work with xml. Could anyone explain this behavior?
     * replaces one file's content with another
     * @param sourceFile
     * @param file_to_overwrite
     * @throws java.io.FileNotFoundException
     * @throws java.io.IOException
    public static void overwriteFile(File sourceFile, File file_to_overwrite) throws FileNotFoundException, IOException {
        BufferedReader br = new BufferedReader(new FileReader(sourceFile));
        BufferedWriter bw = new BufferedWriter(new FileWriter(file_to_overwrite));
        // overwrite destination file w/ source file
        String currentLine = new String();
        while ((currentLine = br.readLine()) != null) {
            bw.write(currentLine);
        br.close();
        bw.close();
    }when the overwritten file is opened in firefox I get this error
XML Parsing Error: no element foundwhen I open up the two documents in notepad to visually inspect, I see some square shaped characters in the original,
but not in the overwritten file.
opening the documents in wordpad shows the overwritten file to be all on one line whereas the original shows the nested form of the xml document.
Any thoughts or insight?

thank you both for your replies
FileInputStream fis = new FileInputStream(sourceFile);
FileOutputStream fos = new FileOutputStream(file_to_overwrite);
int ch;
while ((ch = fis.read()) != -1) {
    fos.write(ch);
fis.close();
fos.close();this seems to be working perfectly except it cuts off the final tag, <\log>
if i invoke another fos.write after the loop it inputs the value of -1 which is a "y"
what's happening at the end of the loop here?
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
  <record>
    <message>
    <\message>
  </record>
<\log>   <-------  goes missing on overwritten file

Similar Messages

  • Problem copying some files.  Error messages -36 and -50

    I'm trying to backup my user folder onto an external LA Cie drive, and some of the files refuse to copy. The files, it seems, are mostly image or mov. files, and there appear to be dozens of "bad" ones, maybe hundreds. Several tens of thousand have no problem copying, but the bad files foul up the entire process.
    The error messages I tend to get are as follows:
    --"The finder cannot complete the operation because some data in [file name] could not be read or written (error code -36)"
    --"The operation cannot be completed because the item [file name] is locked."
    --I also get error code -50 sometimes.
    Can anyone diagnose this problem and tell me how to fix it?
    Powerbook G4   Mac OS X (10.4.9)  

    Todd--
    First thing I think I'd try would be to see if a different cable helps. Sometimes a bad cable can cause problems with an external disk. Also, make sure nothing but the drive is connected to the PowerBook.
    Second, look at the LaCie web site and see if there's a firmware update for your drive. I found a post on another board where the person had the -50 problem with a LaCie DVD drive that was cured by a firmware update.
    The -36 error means there's a disk I/O error:
    <pre class="command">ioErr = -36, /*I/O error (bummers)*/</pre>Look in your console log at the time you try to copy one of these files. It might have a line something like this:
    <pre class="command">Apr 07 09:00:00 username kernel[0]: disk0s3: I/O error.</pre>The username and disk0s3 parts will change a bit. You can figure out which disk is which using the Terminal application. Just copy and run this command:
    <pre class="command">diskutil list</pre>That'll give you the names and BSD identifiers (which is the diskNsN name) for your drive's partition. That should tell you where the actual error is occuring.
    As for the -50 error, that's an error in the parameter list. That can be caused by copying Mac files to FAT32 formatted partitions. If your LaCie drive is not formatted as Mac OS Extended, you might come up against this problem, too.
    charlie

  • Problem copying Epub files to Sony 505 for library ebooks using Adobe Digital Editions.

    I am using Adobe Digital Editions to copy library ebooks to my Sony 505 using a Vista Home Premium 64 bit machine.
    Adobe PDF files successfully copy and are readable.
    However, when a subsequent copy is done for any Epub book from the library the previously copied PDF files change
    to proprietary on the 505. They are unreadable and show as one page long.  The Epub book is the only library book that is
    now readable.
    I have all of the latest software on the PC (it is only one month old) and the latest firmware on the Sony 505.
    I have also reformatted my internal memory on the Sony 505, but this did not have any affect.
    Any suggestions?

    You could have the issue whereby .acsm files do not get properly registered.
    See http://forums.adobe.com/thread/1213041?tstart=0
    One solution to may issues with ADE2.0 is to use the more reliable v1.7.2,
    Try that and see if it helps.
    Version 1.7.2, it is a little difficult to find, available on Adobe site for Windows and for Mac.
    http://helpx.adobe.com/digital-editions/kb/cant-install-digital-editions.html
    The forum software is sometimes corrupting the link above.  There shouldn't be a blank in 'editio ns.html'.  The following redirects to the same page: http://tinyurl.com/diged172

  • Problems copying large files to external disks

    I have a lot of media and so multiple USB and network based external hard disks.
    I'm having trouble with two in particular that are recent buys. I initially mounted them via a USB hub onto my Time Capsule, but when I had errors, I've now tried mounting them directly to my MacBook Air - and for comparison directly to a Windows laptop.
    And I'm only having problems when it's a Mac doing the copying (MBA to either USB mounted via Time Capsule or directly USB mounted on the MBA).
    The problem is that the drive appears to behave OK for initial copies - but I'm trying to put a set of old movies (captured from a VCR ages ago that I'd recorded off TV) onto one of the drives and (a) it takes ages to copy and (b) eventually I get a write failure. The specific error message is
    The Finder can't complete the operation because some data in "" can't be written. (Error code -36)
    I"ve tried a whole variety of setups - as I've said via Time Capsule and directly mounted. I also wondered if the file system on the drive would make a difference. Out of the box it was formatted with FAT32 and when that failed I've now reformatted with MacOS file system - which I would have thought would give better compatibility (and I've read that FAT32 has a large file size limit - although I think it's 4GB and while I do have one file at 4.04GB, it's not failing the copy on that file).
    I've also connected the drive (when formatted FAT32) to a Windows laptop and (a) it copies faster and (b) it copies successfully.
    Any suggestions for this? Is there some kind of large file (all are >1GB) copy issue with USB mounted devices in OSX?

    As I mentioned in my original post while the disks were originally formatted FAT32 I reformatted then and changed them to Mac OS Extended (Journaled) so that isn't the issue. I still have the problem with the disks using Apple format.
    I've noticed that if I do the copy in pieces, it seems to work. I.e. if I select the full set of 45GB in one copy and paste operation (dragging and dropping using Finder) it fails part way through.
    But if I copy 3/4 movies at a time going back until I have copied all of them then I can get all of them on the disk.
    It suggests to me it's some kind of issue with copying and pasting a very large amount of data in Snow Leopard?

  • Problem copying mts file

    Hi there,
    I am willing to save on my hard disk the content of a SD card that contains mts files that I can access via AVCHD,BDMV,STREAM.
    When I copy the whole SD card to save on my hard disk, I get an error message saying that the copy cannot proceed because one of the file contains information that cannot be read.
    I was told on this group, that changing the structure of the AVCHD folder should not be changed.
    Can I delete the file that contains a bug ? or will I screw up the AVCHD folder ?
    Thanks in advance for any suggestion and/or advice.
    Ivan

    If I understand your post  correctly, you are unable to make a copy of your SD card because the bad file halts the copy process?
    Since you are unable to make a protection copy of the card before making changes, I would be reluctant to do any modifications as that might have more consequences and you don't have a back-up copy.
    I would use ClipWrap to convert the files from the card  to ProRes ClipWrap will do each file individually, so if one is corrupt it can be safely bypassed.
    ClipWrap costs around US$50, they have a trial period that will transfer the first minute only of each file so you can test it out.
    http://www.divergentmedia.com/clipwrap
    If you are able to make a protection copy of the card, then many cameras have a card structure restore feature (not formatting) called database restore or something like that in their menu. You might check your manual and see if you have that feature.
    MtD

  • Problems copying files from another user that originated from Time Machine

    I bought my wife a new MacBook Pro to replace a 6 or 7 year old iMac, and in the course of setting it up tonight, we've run into a little snag.
    She didn't need or want the vast majority of the stuff on the old drive. So I reinstalled the applications she wanted, and copied a few of her documents. MOST of what she wanted was the iTunes and iPhoto databases.
    I attempted to copy these over via the time machine drive that used to be plugged into the iMac. I was told there are insufficient permissions to do so. No problem. I used Migration Assistant to copy from the external drive, and selected just the items that we wanted copied -- Music and Photos.
    This worked great, except it copied over a new user account that matched the old one (she's using a different/married name now, so the user accounts didn't match up). In and of itself, I couldn't care less if it creates another user as I figured I could always go in, copy what I need from the restored user folder to the new user, and then delete the user account we don't need.
    Unfortunately, that's where I've hit the final snaffu. All the files I need are in a user account for "Heather A" (restored from the Time Machine drive via Migration Assistant). I need to copy those files (Music, Photos in particular) to the user account "Heather T" (the new account we setup when we first booted up the new MBP). However, in Finder, there's a little red circle with a line through it over the icon for those folders within "Heather A", and attempting to even open them (much less copy anything), generates the error "The folder 'Music' can't be opened because you don't have permission to see its contents."
    How do I get around this and/or change the permissions?
    I should note that both the "Heather A" and "Heather T" accounts are administrator accounts, so I'm at a loss as to why this is happening and how to fix it.
    Any help would be greatly appreciated.
    Dan

    Sssuming there still in the transferred account, delete the files you copied over to the new account. Log into the old account, drop all those files and iTunes into her new accounts /Public/Drop Box/, log into the new account, and drag to where you want them. That should resolve the permissions issues.

  • I had to transferr my music files from one computer to another by directly copying the files from the hard drive to a new drive.  Itunes recognized the files and I was able to load in new songs.  The new songs won't sync with ipod.  Ideas?

    To copy the files I had to remove the hard drive and direct copy them to an expansion drive on another machine.  ITunes recognized the copied files and operates correctly on the computer.  I was able to download additional songs to ITunes on the computer without problem.  The IPod however will not recognize the new songs, does an abreviated sync process and gives a message that the IPod cannot sync because files are being used by another application.  It is also does not want to accept the disconnect command.  Any suggestions on how to solve the sync problem?

    how did you save the songs? can you play the songs? have you restarted the computer?

  • From Forms 5.0 I want to copy a file/folder from one location to another.

    Hi,
    I have a question and I really appreciate your help.
    My Question is
    I would like to copy a file/folder from one location to another.
    (For ex: From my Hard disk to a Network folder).
    I want to do this from Oracle Forms 5.0 and my operating system is Windows 2000/NT Workstation.
    At present my users are doing this by using drag and drop windows functionality,
    But now they want to do this by using a GUI screen.
    I would greatly appreciate if somebody can answer my question.
    Thank you very much and have a nice day.
    Thanks & Regards
    Sanjeev.

    Hi Shay,
    Am able to copy the files/folders by doing the follwing.
    Declare
    My_Command Varchar2(1000);
    Begin
    MY_COMMAND := 'XCOPY /E ' ||:FROM_LOC ||' '|| :TO_LOC ;
    HOST(MY_COMMAND);
    End;
    But my problem is am not able to trap the errors.
    Do you have any idea?
    Thanks

  • Problems copying files to a SMB share.

    Hello,
    Having some odd issues since moving to 10.6. It appears to be a combination of two problems.
    We are in a PC based Active Directory environment. The Mac is bound to the AD and has a Mobile account configured. The problem is with copying files to the network Home folder.
    On attempting to copy a file to the network drive I received a "The operation can't be completed because you don't have permission to access some of the items" error. This only seems to effect some files. I checked the permissions on both the file I was attempting to copy and the destination folder. I had full read/write access to both.
    I attempted to copy the file with the terminal and got an error that I was unable to copy the extended file attributes of the file as I did not have permission.
    Using the xattr command I could see that the file had the com.apple.TextEncoding attribute. I used the xattr -d command to delete the attribute and I was then able to copy the file with the Finder. Another file I tested that I could not copy had the com.apple.FinderInfo attribute. Deleting this attribute also allowed me to copy the file.
    It seems that any file with extended file attributes in 10.6 cannot be copied to our SMB shares. I have tested this on all of our 10.6 Macs with exactly the same result. 10.5 has not had the same problem.
    Now for the second problem. After copying the file as part of the testing I attempted to copy the same file over and replace the existing file and got the error "The Finder can't complete the operation because some data in "" can't be read or written (Error code -36)". I attempted to this a number of times and found that approx 50% of the time it does copy with no error. Checking the Console gives me the following message for the times it does give an error :
    27/10/09 4:03:27 PM /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder[153] Allocator race detected: transaction is not verified for -101/2 - test7.txt
    Any light that can be shone on this issue would be great. This means for us that OS X 10.6 is fundamentally broken and can't be installed on any machines.
    -Justin

    Just posted on the Entourage Help Blog: Workaround for saving Office 2008 files to SMB servers in Snow Leopard
    http://blog.entourage.mvps.org/2009/12/workaroundfor_saving_office_2008_files_to_smb_servers_insn.html
    According to Craig, a poster on the microsoft.public.mac.office newsgroup:
    Changing the owner of the share to NETWORK SERVICE will solve the problem. I have tested this on a test share I set up during troubleshooting and it works! I have told my MS support rep about the workaround and she was going to spread it around. She mentioned that Apple appears to have a fix in the works but not to expect it to be released until February!

  • Problems copying and trashing files

    OK - here's what I assume are two seperate issues, or they may be related. (I'm running 10.3.9 on an iBook G4 and attempting to move files to a USB external).
    I have a DVD of jpg photos I was attempted to copy onto an external hard drive. About half of the 400 photos copied fine, then I got an error message midway through the copy saying something relating to at least one of the files being busy (I don't remember exactly, but I think it was the same as the error message I have below).
    I have already dumped the DVD's contents into iPhoto, so I decided to do it the long way and search through iPhoto's library in the finder. I found some of the photos I wanted to copy, and when I attempt to copy them to the same directory as the DVD photos were copied to, I get this message:
    The selected items cannot all be put into the same location, because at least one of them named "**.jpg" is busy.
    I tried to copy individual files, and I get this for multiple files. In some cases, there was already a file with the same name in the target folder, so I trashed the file in the target folder, emptied the trash, tried the individual file again and still get the same message. No program is running with these files, and these aren't the files that were being copied when I got the first message.
    I went back and looked at the target folder and saw all the files that hadn't been copied are in there with a size of 0 kb. When I try to trash these, I get this error:
    Preparing move to "Trash"
    Some of the items you are moving are in use by another application. Moving the items can cause problems with the application using them. Are you sure you want to move the items?
    I can click continue, but I have to do it for every file and there's about 200 of them.
    So two issues: any way to get past the "file is busy" error to copy the files from my iPhoto directory to the target folder on the external? Any way to trash the files without clicking continue 200 times? And is the problem with the target volume or my iBook where the iPhoto library is? (I initially assumed the problem was with the target external, but the files giving me the "busy" error are on the iBook and give the message even when there is no file of the same name on the external.)
    Any thoughts are appreciated.

    Thanks for the response, but it doesn't address the issue I'm having. (To be fair, the issue I'm having is sort of buried in my long initial post, since as is plain from my next post, I'm An Idiot).
    At any rate, what I'm looking for is this: the files that weren't properly copied are now sitting in a folder in my external hard drive, along with the files that were properly copied.
    There are about 200 files which are just filenames with a size of 0k. I can find all these fine by sorting the folder window by size.
    However, whenever I drag them to the trash, an error message pops up telling me the file is in use by another application. I can click on continue, but I get an error message for every file I drag to the trash. I don't feel like clicking continue 200 times, although I suppose I could. I was wondering if there's a way to tell the Finder these files are not actually in use, both to save my mouse finger now and possibly in the future if this problem repeats itself.
    Thanks.

  • Problems copying files to Flash Drive

    I have been having problems copying files in the Finder to a flash drive when total storage exceeds 1gb or so. I recently obtained a 4gb flash drive and tried to copy about 1.5gb of files and the copy process just stops. I have had the same problem with an SD card in a card reader. If I put the SD card into a Sandisk mp3 player, which mounts as a drive, it will copy find. Also, if I take the card or flash drive to a PC, no problem.
    The same issue happens when I try to copy a lot of files from iTunes to a solid state drive. iTunes will go through a "calculation" process and simply not do the copy. It is not because of capacity. I can repeat the process to a folder on my hard drive and it works find. I then copy the folder to my mp3 player.
    I have been trying to do this for over a year now, hopeing that the next OS release would correct the problem, but it hasn't.
    Any ideas?

    In another thread, I found a suggestion to use Disk Utility to check and fix the thumb drive. I did this and there was a minor directory proablem withe the drive. Lo and behold, it now works!

  • Problems with copying & reconnecting files in a Stmp project

    Hi everyone.
    I want to copy files from a project (that I'm currently working on) to a new drive and reconnect them.
    But I'm running into problems. I cannot select 'reconnect files".
    The situation & history (Sorry for the length):
    From FCP, the editor did a 'Send to STP Multitrack Project' with Base layer video + metadata.
    The files were written to an external drive, that is now connected to my computer.
    When I started the projekt on my computer, I first copied the .stmp file + 'Media' & 'Render files" to the MacinthoshHD, the only internal drive I had.
    I started working on the project, and after a couple of days, the system started to give 'disk limit' - messages. Clearly because of the 1-disk situation.
    So today I bought another internal drive. I was expecting trouble when copying and reconnecting files, and I was right.. What I did:
    I copied all files from the MacHD to the new drive, and opened the stmp file from there.
    First I noticed that the Videotrack in STP was still playing from the external drive
    I managed to copy it to the new drive, and 'relocate' it.
    Just when I thought all troubles were over, the 'limit' messages showed up again.
    Reason: It appeared that the paths to all media files were still the 'old' ones, pointing to the MacintoshHD, and even a couple to the external drive..
    Then, I followed the instructions on 'Reconnecting Media Files' in the STP manual,
    but 'reconnect' is greyed out in the menu. Probably because the project thinks nothing needs to be reconnected.
    So what to do?
    What I can think of, is renaming the source map on the Macintosh HD
    STP will then likely ask: Where is...? And I can point to the new location..
    But this solution is tricky.. It will 'destroy' the original paths. And, will STP really give me a chance to restore all fades, files, and so on?
    I hope someone can help me out..
    Thanks in advance,
    Dan

    STP actually creates and places files in more places than we realize. Look in the temporary files folder; in another that's been showing up as Soundtrack Pro Media (different than the edited media folder), and back in Capture Scratch, Audio Renders and Render files. We've just learned that what we're looking for isn't always where we think it should be. And we use mostly an internal raid and then a detached firewire 800 raid which we pull off and use to work remotely on the same project. We have to make sure everything we need for the project has been mirrored onto the external raid. It's been much more challenging in STP3 than it was in STP2

  • JDev 9.0.3 - problem with compiler options to copy resource file types

    Hello,
    Following a quite strange scenario, I found something bizarre related to the project compile options in 9.0.3 production (I assume the same problem was present way before...)
    Let me first present the facts:
    Assume I have in my project one file named noext (with no extension!) and another one file.verylongext. I know it's not best practice, but let's say they are third party files and I would prefer not to touch them.
    I am able to add them to the project sources, in the specified packages, then I update the Project Settings/Compiler/Resource File Types to Copy to Output Directory.
    But, when I compile, I realize that not all my files were copied to classes/. In fact, if I specify ...;noext;file.verylongext, I get only noext copied, while if I specify ...;file.verylongext;noext, I only get file.verylongext.
    I also tried to use only .verylongext, but the result was exactly the same...
    Of course I can copy the files manually, outside JDev, but this is not best practice neither... :)
    As long as JDev 9.0.3 seems to provide support for filtering the files that will be added to a project (see thread Re: update column for details), I don't really see the purpose of filtering again the files that will be transferred to classes/ (apart from the little bug).
    I think it would be far more useful to have the reverse filter, i.e. "Resource File Types not to Copy to Output Directory". JDev team, would it be possible to have this in 9.0.4?
    Thanks,
    Adrian

    >I tried to reproduce the problem and couldn't.
    Nevermind, I will be back on this when I'll have a simple example.
    >One question, is noext and file.verylongext part of your project?
    Well, you know, since I said I have them in my project, it means that I added them there and I checked that they really were added. No offense...
    >One more question, did you enable Scan Source Path to ... in the input paths panel of the pproject properties?
    No, I did not enable this option, since I see all my files in the project and the only source path is project's src.
    But my real point is related to the enhancement request I made. Given the circumstances,
    could you provide the reverse filter, i.e. "Resource File Types not to Copy to Output Directory", in a future version, maybe 9.0.4?
    Thanks,
    Adrian

  • Snapshot copy of file is locked by another process?

    Hey guys,
    &nbsp;
    &nbsp;
    &nbsp;
    I've never run into this before, but I am having an issue where running robocopy to restore a folder and it's contents from the weekly snapshot I get errors on several files that they are currently in use?
    &nbsp;
    The syntax: robocopy Y:\~snapshot\weekly.2015-08-02_0015\Foldername Y:\Foldername-RESTORED /MIR /Z
    &nbsp;
    The error: Error 32 &lt;0x00000020&gt; filepath The process cannot access the file because it is being used by another process.
    &nbsp;
    As a snapshot copy is read-only and there are no other processes currently accessing the files (closed all explorer sessions, unmounted and remounted cifs share, and even rebooted host) to ensure there were no processes using this snapshot and still several files are failing to copy.
    &nbsp;
    if you cancel the process and run it again immediately the last file you hung on, will usually copy just fine, but another one shortly thereafter will hang.
    &nbsp;
    I used the SysInternals Process Explorer program to see if I could see what had those files locked and could find nothing. I check for vscan, and for volume clones based on that snapshot and again found nothing.
    &nbsp;
    Just curious if anybody else had seen this behavior?
    &nbsp;
    Data Ontap 8.2.3 (CDOT)

    Guess may be when you are performing ROBOCOPY at that time snapmirror or snapvault transfer is going on . I would like you check that. Even Dirty snapshot create those problem RegardsRaghuveer(wellsfargo)

  • How to copy a file from one folder to another folder in Linux

    Hello everyone,
    Oracle forms 11g 11.1.2.0.0
    OS: Oracle Linux
    We use webutil to upload files to the application server from the client machine, and stores them in a folder named JOB_DOCS on the application server (This folder is created as a databse directory too). File types are JPEG, GIF, PDF, TXT, BMP, DOC, XLS etc...
    At a later stage when the user tries to view the uploaded documents, this was not getting displayed on the screen
    on our windows server, when the user clicks on the print button we copy the file from the JOB_DOCS folder to the forms\java folder using the below command
    HOST('COPY ' ||d:\JOB_DOCS\test.pdf||' '||'c:\oracle\middleware\as\forms\java\test.pdf ,NO_SCREEN);
    once the file is under the forms\java folder then it is getting displayed on the screen to print or save, and later we remove the file from forms\java folder.
    But my problem here is, recently we have installed our application on Oracle Linux server, and we have JOB_DOCS folder there, and the users can upload files to this folder also. How can we copy the file test.pdf from JOB_DOCS to forms/java in linux?
    And what could be the reson for the document cannot be accessed from the folder where it is saved? We tried giving folder permissions, adding the folder to PATH variable etc.

    For copying and moving directories you can use the cp and mv commands just like you use them with files. Yeah, I know. If you've already tried to copy a directory with cp, you've probably noticed that cp just complains at you. Probably it says something like cp: omitting directory yadda yadda. You see, the cp command wants you to use the -r option if you want to copy a directory with its contents. The -r means "copy recursively":
    $ cp -r dir1 dir2
    The above creates a directory named dir2 whose contents will be identical to dir1. However, if dir2 already exists, nothing will be overwritten: the directory dir1 will be copied into the dir2 directory under the name dir2/dir1.
    When renaming directories, you use the mv command exactly the same way as with files:
    $ mv dir1 dir2
    When dealing with directories, mv works a bit like cp does. If dir2 doesn't exist, the above will rename dir1 to dir2, but if dir2 exists, the directory dir1 will be moved into the dir2 directory under the name dir2/dir1.
    ref http://www.tuxfiles.org/linuxhelp/dirman.html

Maybe you are looking for