How to write to the end of a file

i am tryign to write to the end of a file using bufferwriter and bufferreadear. I am trying to the read the file until i reach the end and then write in the end. I have some code but i dont know how to read until the end of the file.
File file = new  File ("Product.txt");
          FileReader reader = new FileReader (file);
          BufferedReader readBuff = new BufferedReader (reader);
          FileWriter write = new FileWriter(file);
          BufferedWriter writeBuff = new BufferedWriter(write);
          String line = readBuff.readLine();     
// i know i need to put a while loop somewhere around here

I want to write to the end of the file, what do you mean when you say "then write() until you've written that many bytes, which will overwrite the bytes already in the file."
          File file = new  File ("Products.txt");
          FileReader reader = new FileReader (file);
          BufferedReader readBuff = new BufferedReader (reader);
          FileWriter write = new FileWriter(file);
          BufferedWriter writeBuff = new BufferedWriter(write);
          String line = readBuff.readLine();
          long fileSize = file.length();
          readBuff.close();
          writeBuff.close();
          } catch (IOException e){
               System.out.println ("Error -- " + e.toString());
     }

Similar Messages

  • How can i make the end of a text higher than the rest in 3D?

    I'm designing a 3D text for the outlet store of www.badkamermarkt.nl/ and would like to know how I can make the end of the text higher than the rest in 3D.

    Hi,
    Can you attach a comp of what you're trying to accomplish, instead of a live link to a commercial home page?
    Are you wanting to make the country code of the url bigger like this?
    regards,
    steve

  • How can i remove the end pice/pin from my headphones out of my computer?

    how can i remove the end pice/pin of my headphones out of my computer?

    IF you cannot pull it out with your finger tips, you need to take the machine in for service to an Apple Store or AASP. Doing this type of work yourself could seriously damage the computer so it's best left to professionals.

  • How do i activate the end user agreement

    how do i activate the end user agreemenr???

    You don't need to activate EULA's. They are just a simple way for Adobe to show their language skills. Among all the crap that Adobe installs, there are hundreds of (nearly) identical EULA's installed in sometimes more than 40 different languages, just as all those legal text files. On a simple Master Collection install, there are over 200 directories, almost 1800 files and over 1.6 GB of wasted storage due to installing superfluous stuff in God knows how many languages. I have asked for ages to make that simpler and only in 1 single directory, instead of all over the place. Microsoft does this very good, just install in the language of the OS, the language chosen for the installation and possibly the language of the location you are in. Get rid of all the superfluous crap no one needs. Who wants or needs to have EULA's in Arabic, Armenian, Bulgarian, Cantonese, Danish, Finnish, Hungarian, Japanese, Korean, Letvian, Mandarin, Rumenian, Russian, Thai, Turkish and over 30 other different languages, when English is enough?
    Can you imagine the waste of bandwidth with the Cloud when all those 500,000+ subscribers and hopefully for Adobe even more in the future, all have to download more than 1.6 GB of pure garbage, that slows down the downloads, that take up precious disk space and have no value added at all.
    But this seems to be much too complex for them to handle.
    PS. I just realized something that might be important. Having all that crap in all those local languages could be the excuse for the exorbitant price differences in various countries because it adds to 'the cost of doing business locally'. Who would have figured out such a lame excuse???

  • Finding the end of a file.

    How do I find the end of a stream (in this case, a file) using BufferedReader.readLine()?

    <code>
    public class SectorParser1 {
        // Declare variables that will be used
        Scanner sectorScannerIn;        // This is used in the setFileLocation method
        String sectorLocation;          // This is the abs location of the sector
        String currentIn;
        BufferedReader myParser;        // This is the top-level parser that reads
                                        // through the sct file.
        Scanner mySectorScanner;        // This is the second-level parser that
                                        // reads through the sct file.
        BufferedReader myReader;
        // Define constructors for SectorParser1
        public SectorParser1() {
        }   // CLOSE THE SectorParser1() CONSTRUCTOR
        SectorParser1(String sectorLocation) {
            this.sectorLocation = sectorLocation;
        }   // CLOSE THE SectorParser1(String sectorLocation) CONSTRUCTOR
        // Define methods for SectorParser1
        public void setFileLocation() {
            System.out.print("Please enter the exact path to your sector file: ");
            sectorScannerIn = new Scanner(System.in);
            sectorLocation = sectorScannerIn.next();
        }   // CLOSE THE setFileLocation() METHOD
        public String getFileLocation() {
            return sectorLocation;
        }   // CLOSE THE getFileLocation() METHOD
        public int beginParsing() throws IOException {
            myReader = new BufferedReader(new FileReader(sectorLocation));
            boolean cond = true;
            int counter = 0;
            try{ while(cond) {
                currentIn = myReader.readLine();
                if(currentIn.equals("null")){
                    break;
                }else if(currentIn.startsWith(";")) { // Lines in the file that's
                    continue;                         // being read that start with
                } {                                   // a ';' are comments, and
                    counter++;                        // need to be ignored.
                System.out.println(currentIn);
            } } catch (NullPointerException e) {
                System.err.println("Caught NullPointerException.");
            myReader.close();
            return counter;
    }       // CLOSE THE SectorParsing1 CLASS </code>

  • How to open all the pages of a file PDF in Photoshop?

    Hi,
    How to open all the pages of a file PDF in Photoshop?
    Or
    I need to know the amount of Pages in PDF.
    Example:
    >Set MyPhotoshop = CreateObject("Photoshop.PDFOpenOptions")
    Set MyOpenPref = CreateObject("Photoshop.PDFOpenOptions")
    sFileName = "C:\Temp\Myfile.pdf"
    >With MyOpenPref
    .AntiAlias = True
    .Mode = psOpenCMYK
    .Resolution = 72
    .BitsPerChannel = psDocument8Bits
    .CropPage = psBoundingBox
    .Page = 4
    .SuppressWarnings = True
    End With
    >MyPhotoshop.Open sFileName, MyOpenPref
    I need help.
    Thanks

    http://www.ps-scripts.com/bb/viewtopic.php?t=1882
    Have a look at this thread, the last entry has the full code and has everything you need there.
    The answer to knowing how many pages is, you don't need to know!
    You use SL code and no error and no page is opened. Thats the crux of the code.

  • Extra bytes at the end of class file error

    I have created an applet.
    it worked fine when i ran it with appletviewer.
    it ran fine when i opened it with a browser (when it still was on my computer and not on the net).
    now, when i uploaded all the files, when try to open the page where my applet should be, the applet doesn't start and the console writes:
    java.lang.ClassFormatError: Extra bytes at the end of class file ImageHolderNotifier
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(Unknown Source)
         at java.security.SecureClassLoader.defineClass(Unknown Source)
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(Unknown Source)
         at java.security.SecureClassLoader.defineClass(Unknown Source)
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    i tried rebuilding the project and uploading all the .class files from scratch... still, no change :-/
    i have compiled it using eclipse 3.1.0, JDK1.5.0_02.
    my JRE is 1.5.0_02
    i've tried running it both with Internet Explorer and FireFox...

    Works locally but not after uploading.
    Must be uploaded wrong then (ftp ascii??) or it's the web server.

  • HOW CAN U CORRECT THE DATA IN UR FILE WHICH CONTAINS 1 LAKSH RECS

    Hai Frnds,
    i Attend an interview they asked this questions can u know the answeres . tell me .
    In File to file scenario how can we reprocess records which failed records.
    HOW CAN U CORRECT THE DATA IN UR FILE WHICH CONTAINS 1 LAKSH RECS
    Thanks in advance
    thahir

    Hi,
    Refer these links:
    this might help you
    Generic Approach for Validating Incoming Flat File in SAP XI - Part 1
    Generic Approach for Validating Incoming Flat File in SAP XI - Part 1
    validating against schema file for the output XML file
    Informing the sender about bad records
    Regards,
    Nithiyanandam

  • How can I see the information about a file used in a sequence?

    How can I see the information about a file used in a sequence?

    You can use pretty much any two or multiple button mouse on a Mac, right out of the box.
    I use this one: http://www.apple.com/mightymouse/

  • How do I set the default folder for file - open file... ?

    When I save a file, photo, etc., the default folder for OPENING a file becomes the last folder I SAVED to - even after closing and reopening Firefox. Is there a way to maintain the same default folder for opening files?
    Thanks.

    Originally posted by: kwarner.uneedspeed.net
    Well... I found over 200 bugs none of which seemed to talk about setting
    the default folder. I probably missed the relevant bug in the spew.
    I ask a question here as a last resort -- after I've done what I think
    is an appropriate search for answers.
    But thanks for your help in any case.
    Daniel Megert wrote:
    > DemonDuck wrote:
    >
    >> When I need to open a file not in the workspace, I use File -> Open File.
    >>
    >> But the default folder it opens is in C:\Documents and
    >> Setting\Administrator
    >>
    >> I would like File -> Open File to first open in someplace more
    >> reasonable -- like the workspace.
    >>
    >> How do I set the default folder for File -> Open File ????
    >
    >
    > Is your '?' key broken? Check bugzilla there's a feature request
    > regarding your question.
    >
    > Dani

  • In Firefox 4 how can I cause the date on downloaded files to be the current date? (Some are and some are not. In FF3 the dates were ALWAYS the current ones.)

    In Firefox 4 how can I cause the date on downloaded files to be the current date? (Some are and some are not. In FF3 the dates were ALWAYS the current ones.)
    == This happened ==
    Every time Firefox opened
    == I upgraded to Firefox 4 (beta)

    Firefox 3.6.* and earlier set the downloaded file's modification time to the current time. In Firefox 4.0 the behavior has been changed, if a server returns a timestamp telling when the file was last modified (Last-Modified header), it is used instead.
    You can revert to the previous behaviour by using the [https://addons.mozilla.org/en-US/firefox/addon/93121/ Download Timestamp] add-on.

  • BUG: Extra characters at the end of attachment file names

    I received complaints that my attachments didn't open on the PC's of the recipients. After I saw the messages I noticed there were extra characters at the end of their file names. That's why they wouldn't open. When I looked into my sent mail folder it was there as well. The addition took place when I sent the mail, while composing everything looked fine. It took me a while to realize the pattern. There was one extra for every non-ASCII character in the file name.
    Apparently Mail.app is using two different libraries. The other one counts the non-ASCII characters as two while the other doesn't. I don't know whether Finder still uses MacRoman or Unicode, but this seems to relate to double-byte characters.
    The short term solution is to use only ASCII for file names, but that's not what OS X is all about.

    The class files are broken. Recompile them. If you're uploading them, doublecheck if the FTP program used doesn't do mad things with binary files.

  • How can i change the size of PDF files ?

    how can i change the size of PDF files? when i convert documents in the acrobat browser it seems the files become larger then normal pdf files, this is, i compare with other files that people send to me and i realise that they are smaller than my converted files, even if they have more pages.

    A lot depends on the form of the PDF. Is it graphics, a scan of a text file, pure text, or other? What version of Acrobat are you working with.
    You can do a save as to get a WORD file, but do not expect great results. The ability to get a decent WORD file depends on what the form of PDF you are working from. If it was created from WORD with tags and all, you might get good results. If not, you might get a lot of messed up results.
    Explain what you are starting with and your ultimate goal. Also check the audit of the file (should be under PDF Optimize) to see where the file information is concentrated (text, fonts, graphics, other).

  • How can I copy the whole directory of files from PC to iPad?

    How can I copy the whole directory of files from PC to iPad ?

    Get an app that reads PDF's, such as iBooks or GoodReader or Readdle Docs, then use the file transfer part of iTUnes to get those files to your iPad, through iTunes. ( I have no experience with goodreader, but with ReaddleDocs you can move the files, then create folders to put them in to keep them organized)

  • How can I perform the conversion of pdf files in Cyrillic script to Word files in Cyrillic script. The pdf file is too small for me to read right now. Julyan Watts

    How can I perform the conversion of .pdf files in Cyrillic script to Word files in Cyrillic script. The .pdf file is too small for me to read without a magnifying glass, and the document is more than one thousand pages.

    This answer was not helpful. First of all, I could not find "tech specs"
    anywhere on the Acrobat 11 homepage. And secondly I purchased this software
    for the specific purpose of converting .pdf files to Word. It was only
    after I had completed the purchase that I learnt that Acrobat does not
    permit the conversion of .pdf files in Cyrillic to Word files  in Cyrillic.
    I feel that Acrobat should have provided this crucial information before I
    allowed my credit card to be debited. That is why I  am now asking for my
    money back. But thanks for your attempt to solve my problem, even if it was
    not successful.
    Julyan Watts

Maybe you are looking for