Example usage for java.io BufferedWriter close

List of usage examples for java.io BufferedWriter close

Introduction

In this page you can find the example usage for java.io BufferedWriter close.

Prototype

@SuppressWarnings("try")
    public void close() throws IOException 

Source Link

Usage

From source file:Main.java

public static void writeNewFile(String filePath, String fileContents) {
    File f = new File(filePath);
    if (f.exists()) {
        f.delete();//from w  w  w .  jav a2s . c om
    }

    try {
        // Create file 
        FileWriter fstream = new FileWriter(f);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(fileContents);
        //Close the output stream
        out.close();
    } catch (Exception e) {
        Log.d(TAG, "Failed to create " + filePath + " File contents: " + fileContents);
    }
}

From source file:Main.java

public static void writeNewFile(String filePath, String fileContents) {
    File f = new File(filePath);
    if (f.exists()) {
        f.delete();/*  ww  w.  j ava2  s .  c o  m*/
    }

    try {
        // Create file
        FileWriter fstream = new FileWriter(f);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(fileContents);
        //Close the output stream
        out.close();
    } catch (Exception e) {
        Log.d(TAG, "Failed to create " + filePath + " File contents: " + fileContents);
    }
}

From source file:Main.java

/**
 * Saves passed string to file//  ww w.  j a  va 2 s.  c  o m
 *
 * @param filename      path to file
 * @param stringToWrite string to save
 */
public static void stringToFile(String filename, String stringToWrite) {
    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
        writer.write(stringToWrite);
        writer.flush();
        writer.close();
    } catch (Exception ignored) {
    }
}

From source file:com.reversemind.glia.test.go3.java

public static void save(String fileName, String string) throws Exception {

    BufferedWriter bw = new BufferedWriter(new FileWriter(new File(fileName)));
    bw.write(string + "\n");
    bw.flush();//  w  w w  .  j  ava  2 s .com
    bw.close();

}

From source file:Main.java

public static void saveBoardToExternal(Context context, String fileName, JSONObject jsonObject) {
    File file = new File(getDirectoryBoards(), fileName);
    if (file.exists()) {
        file.delete();//from w  ww .  j  a v a 2s .co  m
    }

    try {
        file.createNewFile();
        BufferedWriter buf = new BufferedWriter(new FileWriter(file, true));
        buf.append(jsonObject.toString());
        buf.close();
        addTomMediaScanner(context, file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static boolean writeXMLFile(String outFileName, String xmlFile) {
    BufferedWriter writer;
    try {//w w w  . ja v  a 2s.  c om
        writer = new BufferedWriter(new FileWriter(outFileName, false));
        writer.write(xmlFile);
        writer.close();
        return true;
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}

From source file:Main.java

public static void write(String text, File dst) throws IOException {
    BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(dst));
    bufferedWriter.write(text);/*from  w  w  w.j av a2s  . c  om*/
    bufferedWriter.flush();
    bufferedWriter.close();
}

From source file:com.egt.core.db.ddl.Writer.java

private static void execute(String vm, Map clases) {
    //      Utils.println("*** combinar(" + vm + ", clases=" + clases.size() + ") ***");
    if (clases == null || clases.size() == 0) {
        return;//ww  w.j a  v a2  s.c  o m
    }
    try {
        Template template = Velocity.getTemplate(vm);
        VelocityContext context = new VelocityContext();
        context.put("clases", clases);
        StringWriter sw = new StringWriter();
        template.merge(context, sw);
        String filename = vm.replace(".vm", ".sql");
        FileWriter fileWriter = new FileWriter(filename);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write(sw.toString());
        bufferedWriter.close();
    } catch (ResourceNotFoundException ex) {
        ex.printStackTrace();
    } catch (ParseErrorException ex) {
        ex.printStackTrace();
    } catch (MethodInvocationException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static Process execute(String command) throws Exception {
    final Process process = new ProcessBuilder("sh").redirectErrorStream(true).start();

    BufferedWriter stdOutput = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

    stdOutput.write(command + "; exit\n");
    stdOutput.flush();/*from   w ww  .  j  a v a 2s.c o  m*/
    stdOutput.close();

    return process;
}

From source file:com.lunix.cheata.utils.file.FileManager.java

public static void createFile(String fileName) {
    try {//  ww  w . j av a2  s . c  o m
        BufferedWriter writer = new BufferedWriter(new FileWriter(new File(dir.getAbsolutePath(), fileName)));
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}