Results 1 to 3 of 3
  1. #1
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default append csv file?

    Hello, I am trying to add to a file without overwriting what I have written into it beforehand. I believe this is called "appending" --where you add to a file but don't overwrite. I'm curious about how to append in Java, I understand how to do it in C but I'm not sure how to go about it here. I was going to start having Java input user information into cell (14,3) however the 13 rows before that are occupied with information. If I simply type in what I have for println those rows will be overwritten with spaces. My question is how can I avoid this? How can I append a .csv file?

    Java Code:
    public class CsvFileWriter {
       public static void main(String[] args){
           try{ 
           String fileName = "out.csv";
            PrintWriter outputStream=new PrintWriter(fileName);
            outputStream.println("\n\n ,,,,,,,,,,,,,,stuff,should,be,in,different,columns"); //successfully puts things in different columns
            outputStream.close();//flushes data to file
            System.out.println("CSV Success");
            
        } 
        catch(FileNotFoundException e){
        System.out.printf("YOU MESSED UP");
    }   
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: append csv file?

    Look at the FileOutputStream class's constructors. One has an append option.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: append csv file?

    And PrintWriter has a constructor that accepts an OutputStream :)

    https://docs.oracle.com/javase/8/doc...intWriter.html

    https://docs.oracle.com/javase/8/doc...putStream.html

    So you need to see how to put the two together.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. how do I append to a file
    By roofninja in forum New To Java
    Replies: 4
    Last Post: 07-30-2012, 01:04 PM
  2. Replies: 2
    Last Post: 04-02-2012, 01:59 PM
  3. Append to file
    By berkeleybross in forum CLDC and MIDP
    Replies: 9
    Last Post: 06-18-2010, 11:42 AM
  4. How to Append in file ?
    By Hippo in forum New To Java
    Replies: 2
    Last Post: 03-19-2010, 01:50 PM

Posting Permissions

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