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

/**
 * Returns only one line from the server's response. This method should be
 * used if the server returns only a single line of String.
 *
 * @return a String of the server's response
 * @throws IOException//w w  w  .j a v a2s . c om
 *             thrown if any I/O error occurred
 */
public static String readSingleLineRespone() throws IOException {
    InputStream inputStream = null;
    if (httpConn != null) {
        inputStream = httpConn.getInputStream();
    } else {
        throw new IOException("Connection is not established.");
    }
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

    String response = reader.readLine();
    reader.close();

    return response;
}

From source file:Main.java

public static String getCPUInfo() {
    try {/*from   www .j a v  a  2 s . com*/
        FileReader fr = new FileReader("/proc/cpuinfo");
        BufferedReader br = new BufferedReader(fr);
        String text = br.readLine();
        String[] array = text.split(":\\s+", 2);
        br.close();
        return array[1];
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

private static String readFileAsString(File file) throws IOException {
    String line;//from w  w  w . j a v a2 s  .c om
    StringBuffer sb = new StringBuffer();
    BufferedReader br = new BufferedReader(new FileReader(file));
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }

    br.close();
    return sb.toString();
}

From source file:Main.java

public static String readFileAsString(File inputFile) throws IOException {
    String finalResult = "";
    String str;//from   w  w  w  .j av  a  2 s .  c  o m
    BufferedReader in = new BufferedReader(new FileReader(inputFile));
    while ((str = in.readLine()) != null) {
        finalResult += str;
    }
    in.close();
    return finalResult;
}

From source file:Main.java

public static int getFileLines(File file) {
    if (!file.canRead() || !file.isFile()) {
        Log.w(LOG_TAG, CLASS + ": getLinesInFile: invalid file.");
        return -1;
    }/*from ww  w .  ja  va2  s  .c o m*/

    int lines = 0;
    try {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        while (reader.readLine() != null)
            lines++;
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return lines;
}

From source file:Main.java

public static String getStringByFile(File f) throws IOException {
    StringBuilder builder = new StringBuilder();
    BufferedReader br = new BufferedReader(new FileReader(f));
    String line;/*from ww  w.  j av a  2 s. c  o m*/
    while ((line = br.readLine()) != null) {
        builder.append(line);
    }
    br.close();
    return builder.toString();
}

From source file:Main.java

public static String stringFrom(InputStream stream, String encoding) {
    StringBuilder builder = new StringBuilder();
    try {/*from   ww  w . ja  v a2  s .  c  o m*/
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, encoding));
        while (reader.ready())
            builder.append(reader.readLine());
        reader.close();
    } catch (IOException ie) {
    }
    return builder.toString();
}

From source file:Main.java

public static String readFile(File file) throws IOException {
    BufferedReader br = new BufferedReader(new FileReader(file));
    String l, line = "";
    while ((l = br.readLine()) != null)
        line += l;//from  ww  w  . j  a v  a  2s  .c o  m
    br.close();

    line = line.replace("\t", "");

    int begin = line.indexOf("<!--");
    while (begin > 0) {
        int end = line.indexOf("-->") + 3;
        if (end > begin) {
            line = line.replace(line.substring(begin, end), "");
            begin = line.indexOf("<!--");
        } else
            throw new RuntimeException("Comment opened but not closed!");
    }

    return line.substring(line.indexOf('>') + 1);
}

From source file:Main.java

private static String read(InputStream is) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader bf = new BufferedReader(new InputStreamReader(is), 1000);
    String str = null;// ww  w .j  a v a2 s  .c om
    while ((str = bf.readLine()) != null) {
        sb.append(str);
    }
    bf.close();
    bf = null;
    return sb.toString();
}

From source file:jp.ac.titech.cs.se.sparesort.Main.java

public static List<String> loadStringListFromFile(String path) throws Exception {
    List<String> events = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(new FileReader(path));

    String line = null;/*w w w .j a  va 2 s. com*/
    while ((line = reader.readLine()) != null) {
        events.add(StringUtils.chomp(line));
    }

    reader.close();
    return events;
}