How to append text to file using FileOutputStream() in Java

1 Answer

0 votes
package javaapplication1;

import java.io.FileOutputStream;
import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) {

        String sFileName = "d://data.txt";

        try {

            try (FileOutputStream fos = new FileOutputStream(sFileName, true)) {
                String s = "c++";
                fos.write(s.getBytes());
            }
       
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }
}


/*
      
run:

java
c
c++
  
 */

 



answered Nov 13, 2016 by avibootz

Related questions

1 answer 189 views
3 answers 293 views
1 answer 290 views
1 answer 156 views
1 answer 196 views
1 answer 192 views
...