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

static String loadPage(String name) throws Exception {
    StringBuffer output = new StringBuffer();
    FileReader file = new FileReader(name);
    BufferedReader buff = new BufferedReader(file);
    boolean eof = false;
    while (!eof) {
        String line = buff.readLine();
        if (line == null)
            eof = true;/*from  w  w w  .j av  a 2  s  .c  o m*/
        else
            output.append(line + "\n");
    }
    buff.close();
    return output.toString();
}

From source file:Main.java

/**
 * Get the last 500 lines of the application logcat.
 *
 * @return the log string.//from   w  w w  . j av a  2s  . c o m
 * @throws IOException
 */
public static String getLogcat() throws IOException {
    String[] args = { "logcat", "-v", "time", "-d", "-t", "500" };

    Process process = Runtime.getRuntime().exec(args);
    InputStreamReader input = new InputStreamReader(process.getInputStream());
    BufferedReader br = new BufferedReader(input);
    StringBuilder log = new StringBuilder();
    String line;

    while ((line = br.readLine()) != null)
        log.append(line + "\n");

    br.close();
    input.close();

    return log.toString();
}

From source file:Main.java

public static String readTextFromFile(Context context, String filePath) throws IOException {
    StringBuilder builder = new StringBuilder();

    AssetManager manager = context.getAssets();
    InputStream stream = manager.open(filePath.replace(ASSET_FOLDER_PREFIX, ""));
    InputStreamReader streamReader = new InputStreamReader(stream);
    BufferedReader bufferedReader = new BufferedReader(streamReader);
    String line;/*from  w  w w.ja va  2s . c o  m*/
    while ((line = bufferedReader.readLine()) != null) {
        builder.append(line);
        builder.append('\n');
    }
    bufferedReader.close();

    return builder.toString();
}

From source file:Main.java

public static String GetIniValue(String filename, String variable) {
    try {//from   w w  w.ja v a2  s. c  o m
        BufferedReader bProcFS = new BufferedReader(new FileReader(filename));
        String readLine = null;
        while ((readLine = bProcFS.readLine()) != null) {
            if (readLine.startsWith(variable)) {
                bProcFS.close();
                return readLine.split("=")[1];
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String fileReadOneLine(String fname) {
    BufferedReader br;
    String line = null;//from  w w  w  .ja v  a2  s  . c o m

    try {
        br = new BufferedReader(new FileReader(fname), 512);
        try {
            line = br.readLine();
        } finally {
            br.close();
        }
    } catch (Exception e) {
        Log.e(TAG, "IO Exception when reading /sys/ file", e);
    }
    return line;
}

From source file:Main.java

public static String getFileContents(Context context, int rawId) throws IOException {
    InputStream raw = context.getResources().openRawResource(rawId);
    BufferedReader buf = new BufferedReader(new InputStreamReader(raw));

    StringBuilder content = new StringBuilder();
    String line;/*from   w  w w  . j  a  v a 2s .  co  m*/
    while ((line = buf.readLine()) != null) {
        content.append(line);
    }
    buf.close();

    return content.toString();

}

From source file:Main.java

public static String readFile(String link) {
    try {/*from  ww w. j av  a  2 s  .c om*/
        // Create a URL for the desired page
        URL url = new URL(link);

        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String text = "";
        String str;
        while ((str = in.readLine()) != null)
            text += str + "\n";
        in.close();
        return text;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return e.getMessage();
    } catch (IOException e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:Main.java

public static String getHardDiskSN(String drive) {
    String result = "";
    try {/*from w  ww  . java2s .  c  o  m*/
        File file = File.createTempFile("realhowto", ".vbs");
        file.deleteOnExit();
        FileWriter fw = new java.io.FileWriter(file);

        String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
                + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"" + drive + "\")\n"
                + "Wscript.Echo objDrive.SerialNumber"; // see note
        fw.write(vbs);
        fw.close();
        Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = input.readLine()) != null) {
            result += line;
        }
        input.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result.trim();
}

From source file:de.e7o.caldav.caldav.Connection.java

public static String InputStreamToString(InputStream is) {
    String t;//from w w w  .  ja  va 2  s  . com
    StringBuilder s = new StringBuilder();
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    try {
        while ((t = br.readLine()) != null)
            s.append(t + "\n");
        br.close();
        return s.toString();
    } catch (Exception e) {
        return null;
    }
}

From source file:com.alibaba.wasp.ZNodeClearer.java

/**
 * read the content of znode file, expects a single line.
 *//*  w w  w  . j  a v  a 2 s .com*/
public static String readMyEphemeralNodeOnDisk() throws IOException {
    String fileName = getMyEphemeralNodeFileName();
    if (fileName == null) {
        throw new IOException("No filename");
    }
    FileReader znodeFile = new FileReader(fileName);
    BufferedReader br = new BufferedReader(znodeFile);
    String file_content = br.readLine();
    br.close();
    return file_content;
}