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 List<String> readFile(Reader simpleReader) throws IOException {
    BufferedReader reader = new BufferedReader(simpleReader);
    List<String> res = new ArrayList();
    String line = null;//from   w  w  w .  java  2s  . c o  m
    while ((line = reader.readLine()) != null) {
        res.add(line);
    }
    reader.close();
    return res;
}

From source file:Main.java

public static double[] read_array(String filename) throws Exception {
    FileReader f = new FileReader(filename);
    BufferedReader inp = new BufferedReader(f);

    String str = inp.readLine();/*from   w w w  . j  ava  2s  .  c  o  m*/
    int nl = 0;
    while (str != null) {
        nl++;
        str = inp.readLine();
    }

    inp.close();
    f.close();

    double[] res = new double[nl];
    f = new FileReader(filename);
    inp = new BufferedReader(f);
    for (int i = 0; i < nl; i++) {
        str = inp.readLine();
        res[i] = Double.valueOf(str).doubleValue();
    }

    inp.close();
    f.close();

    return res;
}

From source file:Main.java

public static String getMotherboardSN() {
    String result = "";
    try {/*w  w w .j  av  a  2 s .  c om*/
        File file = File.createTempFile("realhowto", ".vbs");
        file.deleteOnExit();
        FileWriter fw = new java.io.FileWriter(file);

        String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
                + "Set colItems = objWMIService.ExecQuery _ \n" + "   (\"Select * from Win32_BaseBoard\") \n"
                + "For Each objItem in colItems \n" + "    Wscript.Echo objItem.SerialNumber \n"
                + "    exit for  ' do the first cpu only! \n" + "Next \n";

        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:Main.java

public static String convertStreamToString(InputStream is) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;//from   w  w w .  j av  a 2  s .  c  o  m
    while ((line = reader.readLine()) != null) {
        sb.append(line).append("\n");
    }
    reader.close();
    return sb.toString();
}

From source file:com.baomidou.framework.common.JarHelper.java

public static List<String> readLines(JarFile jarFile, String fileName) throws IOException {
    if (jarFile == null || StringUtils.isEmpty(fileName)) {
        return null;
    }/*  w w  w .j  a  va 2s.co m*/
    List<String> lines = new ArrayList<String>();
    JarEntry entry = jarFile.getJarEntry(fileName);
    InputStream inputStream = jarFile.getInputStream(entry);
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        lines.add(line);
    }
    bufferedReader.close();
    inputStreamReader.close();
    return lines;
}

From source file:Main.java

public static String getStringResponse(HttpResponse response) throws IOException {
    InputStream inStr = response.getEntity().getContent();
    BufferedReader buf = new BufferedReader(new InputStreamReader(inStr));

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

    return xmlContent.toString();
}

From source file:net.idlesoft.android.apps.github.utils.GravatarCache.java

/**
 * Returns a Gravatar ID associated with the provided name
 * // w  w  w .ja  v a  2 s  . c o m
 * @param name
 * @return the gravatar ID associated with the name
 */
public static String getGravatarID(final String name) {
    String id = "";
    try {
        final File gravatars = ensure_directory(ROOT_DIR);
        final File gravatar_id = new File(gravatars, name + ".id");

        if (gravatar_id.isFile()) {
            final FileReader fr = new FileReader(gravatar_id);
            final BufferedReader in = new BufferedReader(fr);
            id = in.readLine();
            in.close();
        } else {
            id = getGravatarIdFromGithub(name);
            if (!id.equals("")) {
                final FileWriter fw = new FileWriter(gravatar_id);
                final BufferedWriter bw = new BufferedWriter(fw);
                bw.write(id);
                bw.flush();
                bw.close();
            }
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return id;
}

From source file:Main.java

public static String convertStreamToString(InputStream is) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line;/*from  ww w  .ja v  a  2 s .  c  om*/
    while ((line = reader.readLine()) != null) {
        sb.append(line).append("\n");
    }
    reader.close();
    return sb.toString();
}

From source file:Main.java

public static String readString(File file) {
    StringBuilder builder = new StringBuilder();
    if (!file.exists()) {
        System.err.println("Can't Find " + file);
    }/*from  ww  w.  j  a va 2s . c o m*/

    try {
        BufferedReader in = new BufferedReader(new FileReader(file));
        String str;
        while ((str = in.readLine()) != null) {
            //System.out.println(str);
            builder.append(str);
        }
        in.close();
    } catch (IOException e) {
        e.getStackTrace();
    }
    return builder.toString();
}

From source file:Main.java

public static String getFile(final String filename) {
    String s = "";
    final File f = new File(filename);

    if (f.exists() && f.canRead()) {
        try {/*from w  ww. ja v  a 2s  . c  o m*/
            final BufferedReader br = new BufferedReader(new FileReader(f), 256);
            String buffer = null;
            while ((buffer = br.readLine()) != null) {
                s += buffer + "\n";
            }

            br.close();
        } catch (final Exception e) {
            Log.e(TAG, "Error reading file: " + filename, e);
            s = null;
        }
    }
    return s;
}