Java FileWriter Write save2File(String fileName, String content)

Here you can find the source of save2File(String fileName, String content)

Description

save File

License

Apache License

Declaration

public static int save2File(String fileName, String content) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static int save2File(String fileName, String content) {
        File file = new File(fileName);
        try {/*from   w  w w .j a v a 2  s.  co m*/
            // if the file is not exist, create it!
            if (file.exists() == false) {

                file.createNewFile();

            }
            // the second parameter is 'true' means add contents at the end of
            // the file
            FileWriter writer = new FileWriter(fileName);
            writer.write(content);
            writer.close();
            return 1;
        } catch (IOException e) {
            e.printStackTrace();
            return 0;
        }

    }
}

Related

  1. save(String fileName, Object o)
  2. save(String fileName, String dataToSave)
  3. save(String modelo, String filename)
  4. save(String targetDir, String filename, String textToSave)
  5. save2DArray(float[][] data, String filePath)
  6. save_array(double[] array, String fname)
  7. saveAllToFile(String filename, String... strings)
  8. saveArrayNames(int[] array, String[] names, String fname)
  9. saveAuthFile(String fileName, String raw)