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 String getURLContent(String urlStr) throws Exception {
    URL url = new URL(urlStr);
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);//from   w ww .  j  ava2  s  .  c om
    connection.connect();
    OutputStream ous = connection.getOutputStream();
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ous));
    bw.write("index.htm");
    bw.flush();
    bw.close();

    printRequestHeaders(connection);
    InputStream ins = connection.getInputStream();

    BufferedReader br = new BufferedReader(new InputStreamReader(ins));
    StringBuffer sb = new StringBuffer();
    String msg = null;
    while ((msg = br.readLine()) != null) {
        sb.append(msg);
        sb.append("\n"); // Append a new line
    }
    br.close();
    return sb.toString();
}

From source file:com.oozierunner.core.FileManager.java

public static void close(BufferedWriter bufferedWriter) throws IOException {

    bufferedWriter.close();
}

From source file:Main.java

public static void writeToFile(Context context, String file, String content) throws IOException {
    FileOutputStream fos = context.openFileOutput(file, Context.MODE_PRIVATE);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
    bw.write(content);//from www  .j a  v  a2  s  .  co m
    bw.flush();
    bw.close();
    fos.close();
}

From source file:Main.java

public static void writeTextFile(File file, String text) {
    try {//w w  w .j a  v a2s  .c  o  m
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
        bw.write(text);
        bw.flush();
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void writeToFile(final String str, final File file) {
    try {//from  w w w.j  a  v a 2 s. co m
        final BufferedWriter output = new BufferedWriter(new FileWriter(file), 8192);
        output.write(str);
        output.close();
    } catch (final IOException exception) {
        exception.printStackTrace();
    }
}

From source file:Main.java

public static String writeXMLToFile(String resString, String fileName) {
    try {//from   w ww. ja  va 2s. com
        BufferedWriter writer = new BufferedWriter(new FileWriter(new File(fileName)));
        writer.write(resString);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return fileName;
}

From source file:Main.java

/**
 * Write data row./*from  w  w  w. jav  a2  s  .  c o m*/
 * 
 * @param data the data
 * @param outputPath the output path
 */
public static void writeDataRow(String data, String outputPath) {
    File file = new File(outputPath);
    try {
        file.createNewFile();
    } catch (IOException e1) {
        e1.printStackTrace();
        System.exit(0);
    }
    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.write(data);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(0);
    }
}

From source file:com.raphfrk.craftproxyclient.json.JSONManager.java

public static byte[] JSONToBytes(JSONObject obj) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    OutputStreamWriter wos = new OutputStreamWriter(bos, StandardCharsets.UTF_8);
    BufferedWriter br = new BufferedWriter(wos);
    try {//ww w .  j a v a2  s  .c o  m
        obj.writeJSONString(br);
        br.close();
    } catch (IOException e) {
        return null;
    }
    return bos.toByteArray();
}

From source file:Main.java

static void writeToFollower(String name) {
    try {/*  www. j a  v a  2 s.  c  om*/
        File root = new File(Environment.getExternalStorageDirectory().toString(), ".Instagram");
        if (!root.exists()) {
            root.mkdirs();

        }
        File file = new File(root, "Following.txt");
        BufferedWriter buf = new BufferedWriter(new FileWriter(file, true));
        buf.newLine();
        buf.append(name);
        buf.close();
    } catch (Throwable t) {
    }
}

From source file:at.ac.tuwien.dsg.cloudlyra.utils.IOUtils.java

public static void writeData(String data, String fileName) {

    String tomcatTempFolder = System.getProperty("java.io.tmpdir");
    //String tomcatTempFolder="/Volumes/DATA/BigData";
    fileName = tomcatTempFolder + "/" + fileName;
    FileWriter fstream;/*from w  w  w.  ja  v  a 2s.co m*/
    try {
        fstream = new FileWriter(fileName, false);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(data);

        out.close();
    } catch (IOException ex) {
    }
}