Android Text File Write write(File file, String content)

Here you can find the source of write(File file, String content)

Description

write

Declaration


public static void write(File file, String content) 

Method Source Code

//package com.java2s;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;

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

import java.util.List;

public class Main {

    public static void write(File file, List<String> content) {

        try {//from   w ww . j ava  2  s.  co  m

            BufferedWriter wtr = new BufferedWriter(new FileWriter(file));
            for (String c : content) {
                wtr.write(c);
            }

            wtr.flush();
            wtr.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void write(File file, String content) {

        try {

            BufferedWriter wtr = new BufferedWriter(new FileWriter(file));

            wtr.write(content);

            wtr.flush();
            wtr.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. write(File file, List content)
  2. write(File file, String s)
  3. write(File file, String s, boolean lazy)
  4. write(File file, String s, boolean lazy, boolean append)
  5. write(String fileName, String s)