Example usage for java.io BufferedReader close

List of usage examples for java.io BufferedReader close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:Main.java

public static JSONObject readJSONFile(String path) {
    String file = new String(), tmp;
    try {/*from   w w w .  j  av a  2  s .c o  m*/
        // Read the file
        BufferedReader bf = new BufferedReader(new FileReader(new File(path)));
        while ((tmp = bf.readLine()) != null) {
            file += tmp;
        }
        bf.close();

        // Parse the JSON
        JSONObject jso = new JSONObject(file);
        return jso;
    } catch (JSONException e) {
        Log.e("JSO reading", "Error parsing the JSO file " + path + "\n" + e.getMessage());
    } catch (IOException e) {
        Log.e("JSO reading", "Error reading the file " + path + "\n" + e.getMessage());
    }

    return null;
}

From source file:Main.java

public static String getJsonAsString(String filename, Context context) throws IOException {
    AssetManager manager = context.getAssets();
    StringBuilder buf = new StringBuilder();
    InputStream json = manager.open(filename);
    BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
    String str;//from   w  w w. j a  v  a2s.co m

    while ((str = in.readLine()) != null) {
        buf.append(str);
    }

    in.close();

    return buf.toString();
}

From source file:Main.java

public static String pegaCabecalho(String nomeArq) {

    String cabecalho = "";
    try {/* w w w  .ja  v a  2s .  c  om*/

        BufferedReader txtBuffer = new BufferedReader(
                new InputStreamReader(new FileInputStream(nomeArq), codificacao));
        cabecalho = txtBuffer.readLine();
        txtBuffer.close();
    } catch (IOException e) {
        System.out.println("[ERROR] Erro ao buscar cabecalho do arquivo: " + nomeArq);
        System.exit(-1);
    }

    return cabecalho;

}

From source file:Main.java

public static String readString(InputStream inputStream) throws Exception {
    BufferedInputStream stream = new BufferedInputStream(inputStream);
    StringBuilder answer = new StringBuilder();
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    String line;//from   w  w w.  ja  v  a 2  s .  c om
    while ((line = reader.readLine()) != null) {
        answer.append(line);
    }
    reader.close();
    return answer.toString();
}

From source file:Main.java

public static String readFile(Context context) {

    String tempo;//from   w ww  . ja v a2  s .c  o  m
    String contenuDuFichier = "";

    InputStream input = null;
    try {

        input = context.getResources().getAssets().open("ManualText.txt");
        BufferedReader bfr = new BufferedReader(new InputStreamReader(input));
        while ((tempo = bfr.readLine()) != null) {
            contenuDuFichier += tempo;
        }
        bfr.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return contenuDuFichier;
}

From source file:Main.java

/**
 * Write the provided String, line by line, in the provided OutputStream.
 *//* ww  w. ja  v a  2  s . com*/
private static void writeStream(String toWrite, OutputStream out) throws IOException {
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
    BufferedReader reader = new BufferedReader(new StringReader(toWrite));
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        writer.write(line);
    }
    reader.close();
    writer.close();
}

From source file:Main.java

public static String[] readTextFile(String filename) throws IOException {
    List<String> wordList = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(new FileReader(filename));
    String line;/*from  w w w . jav  a  2  s .  c  o  m*/
    while ((line = reader.readLine()) != null) {
        wordList.add(line);
    }
    reader.close();
    String[] words = new String[wordList.size()];
    wordList.toArray(words);
    return words;
}

From source file:Main.java

public static String readInternalFileContent(Context content, String fileName) {
    String file = new String(), tmp;
    try {//from w  ww  .  j av  a 2s .  com
        // Read the file
        BufferedReader bf = new BufferedReader(new InputStreamReader(content.openFileInput(fileName)));
        while ((tmp = bf.readLine()) != null) {
            file += tmp;
        }
        bf.close();
    } catch (IOException e) {
        Log.e("JSO reading", "Error reading the file " + fileName + "\n" + e.getMessage());
    }
    return file;
}

From source file:Main.java

static String getSetting(String name) {
    File file = new File(Environment.getExternalStorageDirectory().toString() + "/.Instagram/" + name + ".txt");
    StringBuilder text = new StringBuilder();

    try {//  w w  w .j ava  2 s .c o  m
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
        }
        br.close();
    } catch (IOException e) {
        text.append("Instagram");
    }

    return text.toString();
}

From source file:TheReplacements.java

public static String read(String fileName) throws IOException {
    StringBuffer sb = new StringBuffer();
    BufferedReader in = new BufferedReader(new FileReader(fileName));
    String s;/*from  w w w  .java2s. c om*/
    while ((s = in.readLine()) != null) {
        sb.append(s);
        sb.append("\n");
    }
    in.close();
    return sb.toString();
}