Example usage for java.io BufferedReader readLine

List of usage examples for java.io BufferedReader readLine

Introduction

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

Prototype

public String readLine() throws IOException 

Source Link

Document

Reads a line of text.

Usage

From source file:Main.java

private static String readStringFromStream(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader r = new BufferedReader(new InputStreamReader(in), 1000);
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        sb.append(line);//from  www .  j  a va 2 s  .co  m
    }
    in.close();
    return sb.toString();
}

From source file:Main.java

public static boolean tempMapAvailable() {
    try {//from   w ww .  j  a v  a2 s. c o  m
        FileInputStream instream = new FileInputStream("tempMapSave");
        DataInputStream in = new DataInputStream(instream);
        BufferedReader buffered = new BufferedReader(new InputStreamReader(in));

        if (buffered.readLine() != "null") {
            return true;
        }
    } catch (Exception e) {
    }

    return false;
}

From source file:Main.java

/**
 * Write the provided String, line by line, in the provided OutputStream.
 *///from   w ww  .  ja  v  a2 s .  c o m
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 tabText(String xmlResponse) {
    StringBuffer result = new StringBuffer("");
    try {/*from  www .j a va 2  s .co  m*/
        BufferedReader br = new BufferedReader(new StringReader(xmlResponse));
        String line = br.readLine();
        while (line != null) {
            result.append("\t" + line + "\n");
            line = br.readLine();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result.toString();
}

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 w ww .ja  v  a 2  s  .co  m*/
    while ((line = br.readLine()) != null) {
        builder.append(line);
    }
    br.close();
    return builder.toString();
}

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;
    }//  w  w  w.ja  va 2  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: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  av  a 2s  .  co m*/
    while ((line = reader.readLine()) != null) {
        events.add(StringUtils.chomp(line));
    }

    reader.close();
    return events;
}

From source file:Main.java

public static String getNextSection(BufferedReader bufferedReader) throws IOException {
    String buffer;/*from   www  .java2s .  co  m*/
    do {
        buffer = bufferedReader.readLine();
        if (buffer == null) {
            return null;
        }
        buffer = buffer.trim();
    } while (!buffer.matches("\\[.*\\]"));
    return buffer.substring(1, buffer.length() - 1);
}

From source file:Main.java

private static String getStringFromInput(InputStream in, String format) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, format));
    String cur = bufferedReader.readLine();
    while (cur != null) {
        sb.append(cur);/* ww w.ja v a  2  s . co  m*/
        cur = bufferedReader.readLine();
    }
    return sb.toString();
}

From source file:Main.java

@Deprecated
private static String read(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader r = new BufferedReader(new InputStreamReader(in), 1000);
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        sb.append(line);//from   w  w w  .j  a v a 2 s.  co m
    }
    in.close();
    return sb.toString();
}