Appending string to the start of a file problem

Hi guys,
I've got an xml file which i want to add a dtd to. So i'm using RandomAccessFile to seek the start of the file and write to it, but its seems to be overwriting a small part of my file. My code to this is below:
         try {
         RandomAccessFile f = new RandomAccessFile(xmlMap,"rw");
            f.seek(0);
        //write DTD definition to start of file
         f.writeChars("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"\n"+
                 "<!DOCTYPE map SYSTEM \"mapDTD.dtd\">"+"\n");
         f.close();
         } catch(IOException e) {
              System.out.println("ERROR with file name, game exiting");
              System.exit(1);
         }If i take in this xml file:
<map width="19" height="19" goal="6" name="Hallways of Dooom">
     <random-item type='lantern' amount='5' />
     <random-item type='health' amount='10' />
     <tile x="0" y="0" type="floor" />
     <tile x="1" y="0" type="floor">
          <renderhint>floor:wood</renderhint>
     </tile>
     <tile x="2" y="0" type="floor" />
     <tile x="3" y="0" type="wall" />
     <tile x="4" y="0" type="wall" />
     <tile x="5" y="0" type="wall">
          <renderhint>wall:bricks,cracked</renderhint>
     </tile>it gets overwritten as :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map SYSTEM "mapDTD.dtd">
     <tile x="0" y="0" type="floor" />
     <tile x="1" y="0" type="floor">
          <renderhint>floor:wood</renderhint>
     </tile>
     <tile x="2" y="0" type="floor" />
     <tile x="3" y="0" type="wall" />
     <tile x="4" y="0" type="wall" />
     <tile x="5" y="0" type="wall">
          <renderhint>wall:bricks,cracked</renderhint>
     </tile>I want it so it is :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map SYSTEM "mapDTD.dtd">
<map width="19" height="19" goal="6" name="Hallways of Dooom">
     <random-item type='lantern' amount='5' />
     <random-item type='health' amount='10' />
     <tile x="0" y="0" type="floor" />
     <tile x="1" y="0" type="floor">
          <renderhint>floor:wood</renderhint>
     </tile>
     <tile x="2" y="0" type="floor" />
     <tile x="3" y="0" type="wall" />
     <tile x="4" y="0" type="wall" />
     <tile x="5" y="0" type="wall">
          <renderhint>wall:bricks,cracked</renderhint>
     </tile>
     <tile x="6" y="0" type="wall" />
     <tile x="7" y="0" type="wall" />
     <tile x="8" y="0" type="wall">
          <renderhint>wall:rock,cracked</renderhint>
     </tile>If anyone can see what's going wrong and how i can correct, i would greatly appreciate them saying so.
Thanks a lot.

javaUser wrote:
Hi guys,
I've got an xml file which i want to add a dtd to. So i'm using RandomAccessFile ...That's your mistake. Don't use random access file. It wasn't built for this situation and shouldn't be used for this situation. Do the right thing: rewrite the whole file.

Similar Messages

  • Most efficient way to write 4 bytes at the start of any file.

    Quick question: I want to write 4 bytes at the start of a file without overriding the current bytes in the file. E.g. push bytes 0-4 along... Is my only option writing the bytes into a new file then writing the rest of the file after? RAF is so close but overrides :(.
    Thanks Mel

    I revised the code to use a max of 8MB buffers for both the nio and stdio copies...
    Looks like NIO is a pretty clear winner... but your milage may vary, lots... you'd need to test this 100's of times, and normalize, to get any "real" metrics... and I for one couldn't be bothered... it's one of those things that's "fast enough"... 7 seconds to copy a 250 MB file to/from the same physical disk is pretty-effin-awesome really, isn't it? ... looks like Vista must be one of those O/S's (mentioned in the API doco) which can channel from a-to-b without going through the VM.
    ... and BTW, it took the program which produced this file 11,416 millis to write it (from an int-array (i.e. all in memory)).
    revised code
    package forums;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.nio.channels.FileChannel;
    class NioBenchmark1
      private static final double NANOS = Math.pow(10,9);
      private static final int BUFF_SIZE = 8 * 1024 * 1024; // 8
      interface Copier {
        public void copy(File source, File dest) throws IOException;
      static class NioCopier implements Copier {
        public void copy(File source, File dest) throws IOException {
          FileChannel in = null;
          FileChannel out = null;
          try {
            in = (new FileInputStream(source)).getChannel();
            out = (new FileOutputStream(dest)).getChannel();
            final int buff_size = Math.min((int)source.length(),BUFF_SIZE);
            long n = -1;
            int pos = 0;
            while ( (n=in.transferTo(pos, buff_size, out)) == buff_size ) {
              pos += n;
          } finally {
            if(in != null) in.close();
            if(out != null) out.close();
      static class NioCopier2 implements Copier {
        public void copy(File source, File dest) throws IOException {
          if ( !dest.exists() ) {
            dest.createNewFile();
          FileChannel in = null;
          FileChannel out = null;
          try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            final int buff_size = Math.min((int)in.size(),BUFF_SIZE);
            long n = -1;
            int pos = 0;
            while ( (n=out.transferFrom(in, 0, buff_size)) == buff_size ) {
              pos += n;
          } finally {
            if(in != null) in.close();
            if(out != null) out.close();
      static class IoCopier implements Copier {
        private byte[] buffer = new byte[BUFF_SIZE];
        public void copy(File source, File dest) throws IOException {
          InputStream in = null;
          FileOutputStream out = null;
          try {
            in = new FileInputStream(source);
            out = new FileOutputStream(dest);
            int count = -1;
            while ( (count=in.read(buffer)) != -1) {
              out.write(buffer, 0, count);
          } finally {
            if(in != null) in.close();
            if(out != null) out.close();
      public static void main(String[] arg) {
        final String filename = "SieveOfEratosthenesTest.txt";
        //final String filename = "PrimeTester_SieveOfPrometheuzz.txt";
        final File src = new File(filename);
        System.out.println("copying "+filename+" "+src.length()+" bytes");
        final File dest = new File(filename+".bak");
        try {
          time(new IoCopier(), src, dest);
          time(new NioCopier(), src, dest);
          time(new NioCopier2(), src, dest);
        } catch (Exception e) {
          e.printStackTrace();
      private static void time(Copier copier, File src, File dest) throws IOException {
        System.gc();
        try{Thread.sleep(1);}catch(InterruptedException e){}
        dest.delete();
        long start = System.nanoTime();
        copier.copy(src, dest);
        long stop = System.nanoTime();
        System.out.println(copier.getClass().getName()+" took "+((stop-start)/NANOS)+" seconds");
    output
    C:\Java\home\src\forums>"C:\Program Files\Java\jdk1.6.0_12\bin\java.exe" -Xms512m -Xmx1536m -enableassertions -cp C:\Java\home\classes forums.NioBenchmark1
    copying SieveOfEratosthenesTest.txt 259678795 bytes
    forums.NioBenchmark1$IoCopier took 14.333866455 seconds
    forums.NioBenchmark1$NioCopier took 7.712665715 seconds
    forums.NioBenchmark1$NioCopier2 took 6.206867074 seconds
    Press any key to continue . . .Having said that... The NIO has lost a fair bit of it's charm... testing transferTo's return value and maintaining your own position in the file is "cumbsome" (IMHO)... I'm not even certain that mine is completely correct (?n+=pos or n+=pos+1?).... hmmm..
    Cheers. Keiths.

  • XML Report completes with error due to REP-271504897:  Unable to retrieve a string from the Report Builder message file.

    We are in the middle of testing our R12 Upgrade.  I am getting this error from the invoice XML-based report that we are using in R12. (based on log).  Only for a specific invoice number that this error is appearing.  The trace is not showing me anything.  I don't know how to proceed on how to debug where the error is coming from and how to fix this.  I found a patch 8339196 that shows exactly the same error number but however, I have to reproduce the error in another test instance before we apply the patch.  I created exactly the same order and interface to AR and it doesnt generate an error.  I even copied the order and interface to AR and it doesn't complete with error.  It is only for this particular invoice that is having an issue and I need to get the root cause as to why.  Please help.  I appreciate what you all can contribute to identify and fix our issue.  We have not faced this issue in R11i that we are maintaining right now for the same program which has been running for sometime.  However, after the upgrade for this particular data that the user has created, it is throwing this error REP-271504897.
    MSG-00100: DEBUG:  Get_Country_Description Return value:
    MSG-00100: DEBUG:  Get_Country_Description Return value:
    REP-0002: Unable to retrieve a string from the Report Builder message file.
    REP-271504897:
    REP-0069: Internal error
    REP-57054: In-process job terminated:Terminated with error:
    REP-271504897: MSG-00100: DEBUG:  BeforeReport_Trigger +
    MSG-00100: DEBUG:  AfterParam_Procs.Populate_Printing_Option
    MSG-00100: DEBUG:  AfterParam_Procs.Populate_Tax_Printing_Option
    MSG-00100: DEBUG:  BeforeReport_Trigger.Get_Message_Details
    MSG-00100: DEBUG:  BeforeReport_Trigger.Get_Org_Profile.
    MSG-00100: DEBUG:  Organization Id:  117
    MSG-00100: DEBUG:  BeforeReport_Trigger.Build_Where_Clause
    MSG-00100: DEBUG:  P_Choi
    Report Builder: Release 10.1.2.3.0 - Production on Tue Jul 23 09:56:46 2013
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.

    Hi,
    Check on this note also : Purchasing Reports Fail When Changing Output To XML REP-0002 REP-271504897 REP-57054 (Doc ID 1452608.1)
    If you cant reproduce the issue on other instance, apply the patch on the test instance and verify all the funcionality related to the patch works OK. Then move the patch to production. Or you can clone the prod environment to test the patch.
    Regards,

  • REP-0002: Unable to retrieve a string from the Report Builder message file;

    Hi,
    I've a custom report in which i need to display a large string, of more than 4000 characters. To cater to this requirement i've written a formula column which displays string upto 4k characters and for a string of size beyond 4k i am calling a procedure which uses a temp table having a clob field.
    For a small string the report runs fine but whenever a large string requirement comes into the picture, said procedure gets triggered and i get REP-0002: Unable to retrieve a string from the Report Builder message file.
    OPP log for the same gives an output as under:
    Output type: PDF
    [9/21/10 2:17:12 PM] [UNEXPECTED] [388056:RT14415347] java.io.FileNotFoundException: /app/soft/test1udp/appsoft/inst/apps/e180r_erptest01/logs/appl/conc/out/o14415347.out (No such file or directory)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(FileInputStream.java:106)
         at oracle.apps.fnd.cp.opp.XMLPublisherProcessor.process(XMLPublisherProcessor.java:241)
         at oracle.apps.fnd.cp.opp.OPPRequestThread.run(OPPRequestThread.java:172)
    Report Builder 10g
    BI Publisher's version : 4.5.0
    RDBMS Version : 10.2.0.4.0
    Oracle Applications Version : 12.0.6
    Searched for the same on metalink and found Article ID 862644.1, other than applying patch and upgrading version of BI Publisher is there any other workaround to display a comma seperated string as long as 60k characters, If any please suggest.
    Thanks,
    Bhoomika

    Metalink <Note:1076529.6> extracts
    Problem Description
    When running a *.REP generated report file you get errors:
    REP-00002 Unable to retrieve string from message file
    REP-01439 Cannot compile program since this is a runtime report
    Running the same report using the *.RDF file is successful.
    You are running the report with a stored procedure,
    OR you are running against an Oracle instance other than the one developed on,
    Or, you recently upgraded your Oracle Server.
    Solution Description
    1) Check that the user running the report has execute permissions on any stored
    SQL procedures called. <Note:1049458.6>
    2) Run the report as an .RDF not an .REP , that is remove or rename the .REP
    version of the report. <Note:1012546.7>
    3) Compile the report against the same instance it is being run against.
    <Note:1071209.6> and <Note:1049620.6>

  • Accidentally, I wiped out the start up system files.. How can I start up my Mac HD?

    Accidentally, I wiped out the start up system files in my Macbook
    Air.. How can I start up my Mac HD?

    Reboot your computer. Hold down the option key when you hear the chime sound. Go to the recovery partition. Re-install the operating system. It's easy and doesn't take that long (15 to 30 minutes depending on your computer). By default it does an archive and install meaning that you won't lose your files, just read the screen carefully and you'll be fine. It's not a big deal.

  • TS5179 I've been bitten by the "Missing MSVCR.dll file" problem when downloading the latest iTunes update (PC w/ Win-7 & Outlook-2007#. 'Have followed Apple's instructions of un-installing all Apple software, and re-installing it. #out of space...??)

    I've been bitten by the "Missing MSVCR.dll file" problem when downloading the latest iTunes update, 11.4.62 (on a PC w/ Win-7 & Outlook-2007#. 'Have followed Apple's instructions of un-installing all Apple software, and re-installing it (Ugh).  First result Outlook couldn't find my 1,385 item contact file in iCloud, although the outlook distribution lists were there.  Second result, upon installing iCloud again, I have two iCloud contact files shown in outlook - "iCloud" & iCloud, within iCloud".  1,332 & 1,385 contacts respectively. 
    Plus an iCloud installation error message saying iCloud moved 6,835 files to a "deleted items folder" somewhere.  This is NOT fun at 72-yrs old...!!
    So, how do I make sure I haven't lost anythying from Outlook?   Russ-AZ

    Interesting response, Kappy  -  Back to original post: "First result: Outlook couldn't find my 1,385 item contact file in iCloud, although the outlook distribution lists were there (therefore, initially I had lost my contact file from Outlook).  Second result, upon installing iCloud again, I now have two iCloud contact files shown in Outlook - "iCloud" & iCloud, within iCloud".  W/ 1,332 & 1,385 contacts respectively.  
    Plus an iCloud installation error message saying iCloud moved 6,835 files to a "deleted items folder" somewhere.  This is NOT fun at 72-yrs old...!!
    So, how do I make sure I haven't lost anythying from Outlook?   Russ-AZ"
    You can safely assume that I have tried using it!   So, to make things a little clearer:
         1)  I now have two iCloud "contacts files", w/ a different total count. What's the difference?  Why the different toatl count?
         2)  Since re-installing the Apple software (part of the MSVCR" recovery instructions) "couldn't possible affected Outlook", why am I getting an iCloud installation error message saying iCloud moved 6,835 files to a "deleted items folder" somewhere.  What's in those files? And where are they?
    Probably more important questions get down to:
         3)  Why is a basic Apple product upgrade "screwing-up Outlook"?  This iTunes upgrade, failing to install properly forced Outlook 2007 into a 2-min start-up cycle.  Which was fixed with this "Goat-Rpdeo" of re-installing MSVCR80.dll.
         4)  And under the latest release of iOS-7.0.4 on our iPhones, why is Apple now forcing us to use the iCloud to back-up our contacts, calendars & tasks, vs. allowing these files to be backed-up directly on our PC's via the USB cable?
    Thanks again for your interest and comments.  - Russ-AZ

  • Flush a string to the browser as a file?

    How can I flush a string to the browser and make the browser save it like a file?
    This is what I've got so far:
    String info = "somthing funny here";
    response.setContentType("text/plain");
    response.setHeader("Content-Disposition", "filename=message.txt");
    ServletOutputStream os = response.getOutputStream();
    InputStream is = <somehow get t String info input stream?? >
    int j = 0;
    while ((j = is.read()) != -1) {
        os.write(j);
    os.flush();
    os.close();Thanks!

    Try changing this:
    response.setHeader("Content-Disposition", "filename=message.txt");to this:
    response.setHeader("Content-Disposition", "attachment; filename=message.txt");

  • Appending "something" at the beginning of a file

    Hello,
    I am trying to append a character to the beginning of a file, doesnt seem to work with RandomFileAccess. I first called the seek() methond
    seek(0); //zero to send the file pointer to the front 
    write((byte) myCharValue);apparently it overwrites the value at the front instead of adding for example:
    before running the code the file has: "Java is Cool!"
    after running the code the file has: "xava is Cool!"
    Any Ideas?
    Thanks

    1. Create a new file.
    2. Write out whatever you wanted to insert at the beginning.
    3. Copy the data from the old file and append it to the new file.
    4. Close the files.
    5. Delete the old file.
    6. Rename the new file.

  • Anyone know if the long standing duplicate files problem with File History has been fixed yet?

    There are loads of public threads about the duplicate files problem
    with Windows 8/8.1 File History backup system.
    From all the threads I've looked at, there seems to be no solution,
    and no acknowledgement from MS that they can even repro the problem
    (which surprises me considerably as there are so many people who
    notice the problem).
    Is anyone aware of whether MS (may) have fixed this for Win10?
    Are MS aware of the problem and if they're able to fix it?
    Dave - with many GB of duplicated files in File History :)

    Hmm, is that the attitude MS would recommend? :)
    Why would I care what Microsoft would recommend?
    Clearly you don't, and you appear to have missed my smiley. Calm down
    Noel, many of us are as annoyed by aspects of modern Windows as you
    are. :)
    I'm all about making Windows actually WORK/./
    Aren't we all? Windows is software I use too many hours every day, I
    along with many millions of others need it to work really well. You
    are not alone.
    When they implement something that doesn't work, and even if it did work doesn't do what's needed - and/beyond that/ they remove features people DO need (such as the GUI for Windows Backup), I see no wrong in advising people of the way things
    really are.
    File History essentially does work - it's saved me a couple of times
    in the past couple of weeks. It just has a highly annoying habit of
    creating 100% duplicates of some files for no apparent reason. If MS
    have fixed that I won't have any known complaints about it.
    If you don't like it, you don't have to use it. I generally like it, I
    just want to see that its fixed.
    Dave

  • Best settings to choose at the start? (Game Footage) + Problem

    Greetings Everyone!
    So I have recently bought the CS5 master collection (after ages of labour saving up ) And I like to make videos. Lol. Sooo... I record my game footage with Bandicam (like fraps) , which has a special feature to make all settings aim toward Sony Vegas and Premiere Pro editing. So anyway, after lots of patience and tutorials, I start my sequence and drag some small clips in to edit. BUT! The clip starts out nice and then halfway through it lags like hell! These clips are like 10 seconds long. The origional footage is nice and smooth though.
    This happens with HDV, AVCHD and other settings. Then I export my 10 second clip to see what its actually like out of Premiere Pro and it stutters pretty bad. Hurts my eyes actually lol.
    So my question is - What settings should I select at the start of Premiere Pro CS5 so the clips are smooth and normal and wont stutter when I export them? Is there anything else I should change?
    THANKS FOR YOUR TIME!

    Do not randomly use settings!
    The easy way to insure that your video and your project match
    See 2nd post for picture of NEW ITEM process http://forums.adobe.com/thread/872666

  • Appending data to the beginning of a file

    How do you write data to the first line of a file without overwriting the data which is already present?
    Data before:
    888826759 100011021
    888826767 100011026
    888826916 100011024
    888826916 100011023
    888826940 100011029
    888826940 100011028
    888857389 100011020
    888871480 100011029
    What I want data to look like after:
    ABC
    888826759 100011021
    888826767 100011026
    888826916 100011024
    888826916 100011023
    888826940 100011029
    888826940 100011028
    888857389 100011020
    888871480 100011029
    I'm trying this, but it doesn't work as it overwrites the first piece of data in the file
    file.seek(0);              
    file.writeBytes("ABC");so that the output is:
    ABC826759 100011021
    Edited by: drakester on Oct 12, 2007 10:59 AM

    You might be able to write the file into one of the Collection Lists that maintain order (like LinkedList, but there are others), add the first line, and then rewrite the file from the list. You might also find the Collections methods reverse and rotate could be useful if you add the data at the end of the list.
    You could also create an array and fill the 2nd through last elements with the file lines, insert your data as the first element, then write the file from the array.
    Ther are a number of variations on the above approaches.

  • Does the Start-up Blue Screen problem is solved ???

    Hello.
    I get blue screen on start-up only when I have the secondary screen connected.
    If I start my machine with only monitor, I don't get blue screen.
    I have done all those procedures, including a fresh install, target disk mode, also the
    rm /
    rf /System/Lybrary/SystemConfiguration/ApplicationEnhancer.bundle......even if I had no Application Enhancer EVER installed...
    no success.
    I'm back wih a hope that someone found a fix.
    Thanks.

    Hey Andrew
    I don't have a solution for you, but are you/were you still getting a blue screen ONLY when you have/had a 2nd monitor connected?

  • Nothing but problems from the start...

    From the start, I have had problems:
    1. When I send emails, it lists them twice in my sent folders.
    2. Download ringtones (assigned) that would work whenever they feel like it (random).
    3. Stopped notifiying me when I had messages on Facebook.  It showed I was online and people were sending me chat messages and thought I was ignoring them because I didn't respond.  Later to find out that I had messages... Yes, I checked the notification settings.
    4.  Stopped notifying me when I had emails.  I had to go in to find out I had an email.  Yes, I checked the notification settings.
    5.  Stopped downloading my emails to me at all four days ago and I deleted and reloaded the mail box and it still wont give me anything newer than that.
    6.  The weather wiki on the front screen will randomly show "Benton" when I'm in "Bentonville".
    I'm sure there is more but those are my main concerns right now.  I don't have time to sit on the phone or run to the store every time there is an issue with this ******
    I did a soft-boot, took the battery out, etc., etc.  Any other ideas?

    I've had mine for 48 hours now and I am experiencing the same issues. I sent my wife a picture yesterday and it kept sending her the same email for about 3 hours. I think it sent about 40 copies. Had to delete the message from outbox, reboot twice and it finally stopped. Today, I updated it with the update and I'm getting random reboots, and apps are crashing. I will try to return it today and post back here if anything changes with new hardware.

  • Append strings to file

    Hi,
    How do i modify "write characters to file.vi" such that every time i append a new string to the same file, it will start at a new line?
    There is this parameter in the vi that is called "convert eol"? Read the help file but could not figure out what is a end of line marker. Please help.
    Thanks.

    Hi,
    the easiest way is to concatenate EOL symbol with your string and then write this new string to the file.
    So you will write something like
    EOL"your string". (or "/nyour string" in codes)
    EOL symbol and "Concatenate strings.vi" you can find in "Functions/String/..."
    Good luck.
    Oleg Chutko.

  • Help with copying files into the the Start Menu

    I am trying to copy my application which tracks system usage, such as reboots, temps, etc, I want it when it first runs, to copy it self into the the programs folder and the start up folder. However I get the error ""FileCopy: destination file is unwriteable: ""......Anyone have an idea why I get this error? Is there away around it? Thanks for any and all help
    *Copying on a Mac works fine
    *I am currently Testing it on a copy of Windows Xp
    *I havenot Tested Vista or 7 Yet.
    Hers the class which I call to copy my program
    class FileCopy {
         String OS="";
         String username;
         String dir;
         String name="Test.jar";
         String MAC="Mac OS X";
         String WinXp="Windows XP";
         String WinVista="Windows Vista";
         String Win7="Windows 7";
         JFrame errorWin;
         FileCopy(){
              System.out.println("Enter Copy");
              OS= ManagementFactory.getOperatingSystemMXBean().getName();
              username = System.getProperty("user.name"); 
              if(MAC.compareTo(OS)==0){
                   copyMac();
              else if(WinXp.compareTo(OS)==0){
                   copyWinXp();
              else if(WinVista.compareTo(OS)==0){
                   copyWinVista();
              else if(Win7.compareTo(OS)==0){
                   copyWin7();
              else
                   return;
         private void copyMac(){          
              System.out.println("Enter Mac Copy");
              System.out.println("OS:"+OS);
              String s="/Applications/Solitaire.Jar";
              try {
                   copy(name, s);
              } catch (IOException e) {
                   System.out.println("Failed at Mac Copy new");
                   errorWin=new JFrame("Error: Failed at Mac Copy new ");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
         private void copyWin7(){
              String dir1="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\SolitaireWin7.Jar";
              String dir2="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup\\SolitaireWin7.Jar";
              try {
                   copy(name, dir1);
              } catch (IOException e) {
                   System.out.println("Failed at Win7 Copy 1");
                   errorWin=new JFrame("Failed at Win7 Copy 1");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
              try {
                   copy(name, dir2);
              } catch (IOException e) {
                   System.out.println("Failed at Win7 Copy 2");
                   errorWin=new JFrame("Failed at Win7 Copy 2");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder     
         private void copyWinVista(){
              String dir1="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\SolitaireVista.Jar";
              String dir2="C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup\\SolitaireVista.Jar";
              try {
                   copy(name, dir1);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at Winista Copy 1");
                   System.out.println("Failed at WinVista Copy 1");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
              try {
                   copy(name, dir2);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at WinVista Copy 2");
                   System.out.println("Failed at WinVista Copy 2");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder     
         private void copyWinXp(){
              String dir1="C:\\Documents and Settings\\"+username+"\\Start Menu\\Programs\\Solitaire.Jar";
              String dir2="C:\\Documents and Settings\\"+username+"\\Start Menu\\Programs\\Startup\\Solitaire.Jar";
              try {
                   copy(name, dir1);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at WinXp Copy 1");
                   errorWin.setVisible(true);
                   errorWin.repaint();
                   System.out.println("Failed at WinXP Copy 1");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder
              try {
                   copy(name, dir2);
              } catch (IOException e) {
                   errorWin=new JFrame("Failed at WinXp Copy 2");
                   errorWin.setVisible(true);
                   errorWin.repaint();
                   System.out.println("Failed at WinXP Copy 2");
                   e.printStackTrace();
              } //Moves Jar File to Application Folder     
         public void copy(String fromFileName, String toFileName) throws IOException {
           File fromFile = new File(fromFileName);
           File toFile = new File(toFileName);
           if (!fromFile.exists()){
                errorWin=new JFrame("FileCopy: " + "no such source file: "  + fromFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
             throw new IOException("FileCopy: " + "no such source file: "  + fromFileName);
           if (!fromFile.isFile()){
                errorWin=new JFrame("FileCopy: " + "can't copy directory: "
                           + fromFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
             throw new IOException("FileCopy: " + "can't copy directory: "
                 + fromFileName);
           if (!fromFile.canRead()){
                errorWin=new JFrame("FileCopy: " + "source file is unreadable: "
                           + fromFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
             throw new IOException("FileCopy: " + "source file is unreadable: "
                 + fromFileName);
           if (toFile.isDirectory())
             toFile = new File(toFile, fromFile.getName());
           if (toFile.exists()) {
             if (!toFile.canWrite()){
                  errorWin=new JFrame("FileCopy: destination file is unwriteable: " + toFileName);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination file is unwriteable: " + toFileName);
             System.out.print("Overwrite existing file " + toFile.getName()
                 + "? (Y/N): ");
             System.out.flush();
             BufferedReader in = new BufferedReader(new InputStreamReader(
                 System.in));
             String response = in.readLine();
             if (!response.equals("Y") && !response.equals("y")){
                  errorWin=new JFrame("FileCopy: existing file was not overwritten.");
                   errorWin.setVisible(true);
                   errorWin.repaint();
                  throw new IOException("FileCopy: existing file was not overwritten.");
           } else {
             String parent = toFile.getParent();
             if (parent == null)
               parent = System.getProperty("user.dir");
             File dir = new File(parent);
             if (!dir.exists()){
                  errorWin=new JFrame("FileCopy: destination directory doesn't exist: " + parent);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination directory doesn't exist: " + parent);
             if (dir.isFile()){
                  errorWin=new JFrame("FileCopy: destination is not a directory: " + parent);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination is not a directory: " + parent);
             if (!dir.canWrite()){
                  errorWin=new JFrame("FileCopy: destination directory is unwriteable: " + parent);
                   errorWin.setVisible(true);
                   errorWin.repaint();
               throw new IOException("FileCopy: destination directory is unwriteable: " + parent);
           FileInputStream from = null;
           FileOutputStream to = null;
           try {
             from = new FileInputStream(fromFile);
             to = new FileOutputStream(toFile);
             byte[] buffer = new byte[4096];
             int bytesRead;
             while ((bytesRead = from.read(buffer)) != -1)
               to.write(buffer, 0, bytesRead); // write
           } finally {
             if (from != null)
               try {
                 from.close();
               } catch (IOException e) {
             if (to != null)
               try {
                 to.close();
               } catch (IOException e) {
    }

    That's clearly a security restriction then. You need to assign the JVM's user account enough rights to do so, or to configure any firewall/virusscanner which has possibly blocked it.
    Apart from this, are you aware of the fact that the OS root disk is not per se labeled "C:", that the location of documents is not per se "Documents and Settings", that there exist System#getenv() and System#getProperty() methods to find default system and environment variables and that there is the java.util.prefs API to access the registry? Your application is likely not going to run on any environment.

Maybe you are looking for

  • Output Video Is Ghosted, Mirrored and Upside Down!

    Posted this in the Media Encoder forum since I don't know where this fits best.... Not sure if this is Media Encoder or Premiere... I made a videdo, about 4 minutes long. It's transcoded ProRes, on a PC, version 5,5 of the suite. Basically when I was

  • How to create a directory or Folder  using java program?

    Hi all, Can any one know, how to create a directory(new folder) in java. can any give me some idea, on creating a directory using java program dynamically. thanx in advance

  • I only want quicktime

    I'm new on these forums and was just wondering if there was any way to get just quicktime installed without having to go through the hassle of installing the itunes S**TE? If anyone knows of the best way of doing this then I would like to know asap b

  • Web Dynpro ALV : get_model_extended - example

    Hi, I'm trying to used this method to limit my columns display, if any one can help to give me the example to use this method. Need to pass S_PARAM, i'm not sure what value to be passed. There is note for this, but there is no usage example. [https:/

  • "Cost" column of the VF03

    Hi, Can anybody explain where the "cost" column of the VF03 screen come from (from the material master, condition records or sales document's conditions...)? Thanks in advance?