Need To Urgently Delete Contents of a File! Please

I have flat File that exist in a Directory. I check what its contents is and then I have to overwrite this File. But unfortunately I can't figure out how to overwrite what is alrady on the File. i just seem to add onto the contents.
File f = new File("path" + "filename");
//I need to check if it exist, so that I can decide whether I want to
//create a New File, Modify the File or Pend the File
//I can Pend and I can create a File, but not MOD
f.exists();
RandomAccessFile random = new RandomAccessFile(f, "rw");
//As far as I understand the following command deletes the File
//and returns a boolean the verify whether is has deleted the File or not.
//But it always returns false
f.delete();
random.writeBytes("StringofBytes");If any of can see what I'm doing wrong. Please help me I got a time limit on this one.

"f.delete()" always fails because the file is open. And that's because you yourself opened it in the previous line. First delete f, then create a new version of it.

Similar Messages

  • Need script to delete two MS pref files

    As one who can't script my way out of a paper bag, I come here suitably humbled to request help with a script. 
    Every so often, some of my incoming emails in MS Entourage become unreadable due to garbled fonts.  The solution is two quit MS Entourage and delete two Microsoft preferences files.  I'm looking for a script that would automatically send these two files to the Trash:
    • MS Office font cache
    /Users/ramoncastaneda/Library/Preferences/Microsoft/Office Font Cache (11)  ===>>> delete the “Office Font Cache (11)” file.
    • and MS browser font cache
    /Users/ramoncastaneda/Library/Caches/com.microsoft.browserfont.cache ===>>> delete the "com.microsoft.browserfont.cache" file.
    Thanks in advance for any and all guidance.

    I would strongly recommend becoming more familiar with and more comfortable within Terminal and the command line environment, and preferably sooner rather than later; before you need it.
    The cmmand line environment is the native environment of Mac OS X and Mac OS X Server, and it is the core of how the server operates, and the command line is particularly central to troubleshoot Mac OS X and Mac OS X Server if (when) something goes wrong, and it is how you will configure Mac OS X and Mac OS X Server for many of its more advanced operations and features.
    Bash is the name of one of the command interpreters on Mac OS X and Mac OS X Server.  It is the default command interpreter for the command line environment; what's known as the shell or command shell or command line.
    The command line is also where you can write bash shell scripts, such as the two delete commands that I posted.  A shell script is a file containing command line shell commands.  That three-line shell script is a bash script flag (the so-called "shebang") and the two rm remove commands that delete the two files.
    The pico tool mentioned is a text editor, and an editor with a screen-driven command interface.  That particular pico command puts you into the pico text editor for the specified filename, and where you will have command hints for the editor visible at the bottom of the display.  There are more advanced editors than pico, but pico is a good editor to start with.
    Again; I'd recommend becoming a little more comfortable with the command line; that'll pay dividends far beyond deleting a couple of cache files.

  • I need some help with AVI and IDX files please.

    Hello there,
    I've just been given a hard drive with a load of media on it that I need to work with in FCP.
    There's a folder with many .AVI clips, and each clip has an accompanying directory file with the extension .IDX
    The format of the AVI files is DV, 720x576, 48kHz.
    For the life of me, I can't get FCP to accept the media. Log and Transfer won't accept them, and if i bring in the AVI files in on their own using File>Import>Files... I get a message saying:
    Media Performance Warning
    It is highly recommended that you either recapture the media or use the Media manager to create new copies of the files to improve their performance for multi-stream playback.
    I can click 'OK' for this message and the media will appear in the browser, but If I place one of these AVI files on a new conformed sequence, the audio needs rendering. (Sequence settings correspond to media settings)
    I tried just changing the wrapper from AVI to MOV, thinking I could fool FCP into accepting them, but I get the same rejection.
    I thought the audio and video signals might be muxed, so I tried MPEG Streamclip to sort that out, but even MPEG Streamclip doesn't accept the media, saying : File open error: Can't find video or audio tracks.
    Could anybody advise me on how to get the most out of these media files please?
    Thanks in advance.
    James.
    Message was edited by: James M.
    Message was edited by: James M.

    yes. I tried transcoding in QT, but they still come in with the same audio rendering required. I'm a bit loath to convert them all though, as there are 1400 clips.
    It's not a huge problem, as they do play in FCP, but I'd like to sort out the audio rendering. I don't understand why it needs rendering as the media and sequence audio settings match, and it's not some weird format or anything, it's bog standard 48kHz stereo.

  • Is it possible that a document (in this case an Appleworks or Movie Magic Screenwriter) can be lost forever, but it's contents somehow remain as other file types elsewhere? I have an old hard drive and I need to locate the contents of these files.

    I have a 20 gig hard drive from a 2001 iBook. When my iBook crashed back in '04, there was a screenplay on there that was not saved anywhere else. It has tremendous sentimental value to me, and I would really like to retrieve it. I've ran some data recovery software that's uncovered a gargantuan amount of data, most of it being completely unreadable to me.
    Additionally, I have found an AppleWorks file that could be the script, but it is ZERO bytes in size, and Pages won't even open it, saying that it is not a valid AppleWorks file.
    So I'm curious...is it possible that the document is lost, but somehow the contents of it are somewhere else on the drive as metadata in other unreadable formats. And if that's the case, how would I go about translating the unreadable data back into something that IS readable? 

    Hello,
    toddisalive wrote:
    Additionally, I have found an AppleWorks file that could be the script, but it is ZERO bytes in size, and Pages won't even open it, saying that it is not a valid AppleWorks file.
    if the size of this file is really ZERO bytes, either the original file contained an empty data fork and a resource fork which was stored elsewhere (*) or the file is too damaged to retrieve anything. Moreover, as AppleWorks never generates file with empty data fork, at least to my knowledge, ....
    Concerning the Movie Magic ScreenWriter files, the application seems to exist for Yosemite http://www.write-bros.com/movie-magic-screenwriter.html ( but it seems "expensive"  and I do not know if it accepts to import old files )....
    (*) maybe in .TOTO or __MACOSX/.TOTO if the filename is TOTO

  • Need help urgently!! - "The selected file cannot be linked because its type (video) does not match t

    Hey guys... I need your help!! I started a project using Premiere Pro 2 and was 80% when I formatted my computer (all my project files were always saved to a external hard drive). Anyways instead of installing Premiere Pro 2, I installed Premiere Pro Cs3. Problem is whenever I try starting up my project it asks me to link every file used. When I do this it says "The selected file cannot be linked because its type (video) does not match the original file's type (audio and video)." I took my external harddrive to friend's house who has Premiere Pro 2 and it says the same thing. Why did this happen? Is there anyway around it... Any help would be greatly appreciated, I put over 20 hours into editing this movie... I don't want it all to go to waste.

    Frequently answered question
    Cheers
    Eddie
    Forum FAQ
    Premiere Pro Wiki
    - Over 250 frequently answered questions
    - Over 100 free tutorials
    - Maintained by editors like
    you

  • Need help in deleting photo album...please

    I transeferred a photo album to my idop nano directly from windows without using Adobe Photoshop or any Adobe program..and i cant delete the photo album because the iPhoto menu does not show on my iTunes...?

    Double click the iPod on the desktop and delete the folder you put on there.

  • To Copy the file content to another file and to delete the orginal file.

    Hi ,
    Can you pls let me know how i need to copy the contents of one file to other,
    For e.g   P_FL Consits of following records ( Assume that file need to created on application server)
      This is standard header ( header record)
    name  school class adreess ( item records)
    xyz     abc     1        kkkkk
    jjjj        cba     2       jkjkjkj
    uiui      cab     3       oioioioi
      i need to copy the above mentioned file contents( P-FL) into another file say P_NEWFL.
    so how i need to create this new file and how to copy the content of old file to new file.
    After copying the contents of old file to new file i need to delete old file.

    Sample code to implement this
    PARAMETER: p_file TYPE file DEFAULT 'd:\interface\In\barcoinbound2sap.txt',
               p2_file TYPE file DEFAULT 'd:\interface\In\backup_barcoinbound2sap.txt'.
    START-OF-SELECTION.
      OPEN DATASET p_file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
      OPEN DATASET p2_file IN TEXT MODE ENCODING DEFAULT FOR OUTPUT.
      DO.
        READ DATASET p_file INTO line.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        TRANSFER line TO p2_file.
       IF sy-subrc NE 0.
         EXIT.
       ENDIF.
        SPLIT line AT ',' INTO lit_barco-prodnorder lit_barco-quant lit_barco-machtime lit_barco-duedate.
        APPEND lit_barco.
        CLEAR lit_barco.
      ENDDO.
      CLOSE DATASET p_file.
      CLOSE DATASET p2_file.
    dalete dataset p_file

  • How to read the contents of Uploaded File Data?

    Dear Experts,
    I want to develop one webdynpro application in which the iview contains the FileUpload option.and after uploading i need to read the contents of the file.
    Can you plz guide me how to achieve this?
    its very much helpfull if u have any sample project / code on this...plz do send it to [ycsvissu at gmail dot com]
    Regards,
    Viswes.

    Ike,
    Do you have a sample. I am searched so much in this forum for samples. I looked on SAX Parser. I did not find any samples.
    Please help me.
    Thank you for your posting.
    Padma.

  • Passing contents of text file in oracle cursor

    Hi,
    I need to pass the content of text file in cursor and pass it on to calling codes. then calling codes will generate another text at their end. Can some help how can I pass contents of text file in oracle cursor? Thanks

    i need to do it without tables for some reasons.

  • From browse button of input type=file, can I show the content of a file

    Hi all,
    I am using, input type=file, where browse button appears. I am having a text area. My requirement is after I select the browse button, I need to show the content of the file in the text area. As of now I 've handled by having another button 'show', which should be pressed after browse done. But, How to handle it in the browse button itself, how will I get that action event from browse button. Plz help.
    Regards,
    Sam

    I think someone asked a very similar question here,
    http://forum.java.sun.com/thread.jsp?forum=45&thread=501889
    check the thread, it may help you.
    -S-

  • How to write content of the file under folder

    Hi Experts,
    I have following scenario, I have list of files under folder in local desktop(for eg D:\mani)
    I have only filename, using this filename i want to search and get content of the particular file and write in some other location? how to do that? give your suggestions?
    Regards,
    P.Manivannan

    You could go two ways here:
    The first possibility requires that (a) you know what operating system you are working with, and (b) you only need to copy the file, and not do anything else with the contents of it. In this case, probably the easiest way to do this is to use a Runtime exec command for the file you want to copy:
    java.lang.Runtime.getRuntime().exec( "cp D:\mani D:\mani2" );Otherwise, if you need your code to be portable, you can't assume anything about the operating system. Since java.io.File doesn't provide a copy method, you will need to read the entire contents of the file into the vm, and then write them out to a new file. Also, if you need to use the contents of your file in some other way, as well, then you also need to read the entire contents into the vm. In this second case, how you read the file may depend on what kind of data the file contains.
    In general, the following code should work for you:
    final FileInputSteam  fis = new FileInputStream ( new File( "D:\mani"  ) );
    final FileOutputStream fos = new FileOutputStream( new File( "D:\mani2" ) );
    final byte [] buf = new byte[ 1024 ];
    int bytesRead;
    while ( ( bytesRead = fis.read( buf ) ) != 0 )
        fos.write( buf, 0, bytesRead );Don't forget to catch or throw IOException.
    Hope this helps.
    - Adam

  • Read the content of a file (via socket)

    Hi,
    I need to read the content of a file (.txt, or better, .jpg) and to write it again in another file.
    I have this code (in Javascript):
        conn = new Socket;
        conn.encoding = "BINARY";
        if (conn.open ("127.0.0.1:8888")) {
        conn.timeout=30;
        conn.writeln("GET variousFiles/file.jpg HTTP/1.1");
        reply = conn.read(999999);
        conn.close();
        var file = new File("C:/APPS/New_File.txt");
        file.encoding = 'BINARY';
        var open_file = file.open("w+");
        file.write(reply);
        } else { alert("Errore: " + conn2.error); }
    However my new file is always empty, because I can not read the content of the first file.
    My variable "reply" is always empty.
    Thanks and best regards.

    There is a particular case with sugested function, if content is generated on the fly by the server -php, cgi, etc.-
    In this case, http server doesn´t knows total size of response data, so response shows a chunked transfer-encoding header and data is parted in chunks, each one starting with it´s size, and following the data.
    HTTP/1.1 200 OK
    Date: Tue, 30 Apr 2013 12:43:41 GMT
    Server: Apache/1.3.31 (Win32) mod_fastcgi/2.4.1
    Connection: close
    Transfer-Encoding: chunked
    Content-Type: image/jpeg
    f49
    ÿØÿà  JFIF
    I´m using this function to decode parted response, with initial chunkedString with firs chunk size; in this case, f49:
    PartsSeparator="\r\n";
    function getPartedBody(partedBodyString) {
        var separatorPosition=partedBodyString.indexOf(PartsSeparator);
        var chunkSize=new Number("0x"+partedBodyString.substring(0,separatorPosition));
        separatorPosition+=PartsSeparator.length;
        var bodyString=new String("BINARY");
        bodyString="";
        if (chunkSize>0)
            bodyString=partedBodyString.substring(separatorPosition,separatorPosition+chunkSize)+
                getChunkedResponse(partedBodyString.substring(separatorPosition+chunkSize+PartsSeparator. length));
        return bodyString;
    Hope this helps
    regards

  • Hello, I want to switch form a individual account to a team/business account? Can you please help me? I need this urgent Thank you!

    Hello, I want to switch form a individual account to a team/business account? Can you please help me? I need this urgent Thank you!

    Hi Koen,
    Please refer the following help article under "Purchasing Creative Cloud for Team".
    Creative Cloud Help | Creative Cloud for teams
    Hope this helps.
    Regards,
    Sumit Singh

  • HT1923 In trying to delete the Apple file in the Program/Common File I can delete all contents except the Internet Services folder.  Thus preventing me from deleting the Apple FIle.  Error message says I need permission to delete this file.  How do I proc

    Trying to delete the Apple Folder from Program Files/Common Files.  I can delete all the contents except for the Internet Services folder which prevents me from making the deletion.  The error message says "you need permission to delete this file".
    Discovered this problem when trying to upgrade from my 3G iPhone to a new 5S iPhone unsucessfully.

    See note 3 of Troubleshooting issues with iTunes for Windows updates.
    tt2

  • I deleted all my iTunes files and need help recreating them.

    Hello everyone
    I accidentlly deleted all the iTunes files (NOT the content, just the files iTunes uses in its database). When I tried to create a new database, iTunes moved all my my music videos into the Movies or Home videos, which I don't want. I have a copy of my folder set up that I want iTunes to use and to not alter (exactly as it was before I deleted the files). Here is what I thought I need to do. Please corect me if I am wrong:
    1. remove all the files that iTunes has relocated to different folders (IE, basically delete them all)
    2. copy the folders onto the drive I use for my media
    3. start itunes
    4 unselect Keep my files organized
    5. scan the folders
    6. Select all the music and videos and classify them as "Music" or "Music Videos"
    This should keep all the files in the same folders as the backup copy, without moving them to Videos or Home Videos. I assume this will also retain the current Artist / Album / Song hierarchy.
    Is this correct?
    Any better way to do this?
    Thanks everyone who can help!
    JoHN

    1) If you bought them from Apple you canprobably download them again.
    2) If you back up your computer as you should, they will be on the backup.
    3) If you stop using your computer this instant (because as you use the computer it overwrites deleted files even if you have lots of space), buy recovery software ($100+), there is a  chance you can recover some of them, though they may have lost filenames and will be in quite a mess.

Maybe you are looking for

  • Itunes no longer works after installing 11.1.4

    I installed Itunes 11.1.4 and noww ITUNES will not work. I have uninstalled all apple products and reinstalled, No Luck I have even tried a system restore point three different dates still no luck. I have even gone to Filehippo web site and tried to

  • Will Adobe Flash 8 work with Windows Vista?

    I was just wondering whether anyone knew whether the new WIndows Vista will work fine with Adobe Flash 8? Thanks

  • Help needed on three day old iPod 5!

    My iPod 5 will not connect to iTunes or the App Store, when I touch the iTunes or App Store account it says "cannot connect to iTunes Store". It's 32gb and my brothers is exactly the same and he hasn't had any problems. My iPod is connected to my hou

  • Cross-client customizing are not permitted

    Hi, I am trying to remove "Transformation Object" in BI 7.0, QA server, and it not allowe to me access, I have SAP_ALL access I am getting this error messages: "changes to repository or cross-client customizing are not permitted" I know we can't chan

  • Redirecting a domain URL to a file

    Is there any SAF directive (e.g NameTrans) to redirect a domain URL (e.g http://www.xyz.com/rob.txt) to a file rob.txt sitting at location /x/y/rob.txt (other than root directory rob.txt). Bascially I want to achieve any request coming to http://www.