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

public static String getCPUInfo() {
    try {//from  w ww .  j  ava 2 s . co m
        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

public static String readFileAsString(File inputFile) throws IOException {
    String finalResult = "";
    String str;//www  .  jav  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 String getCpuName() {
    try {/*w  w  w . ja  va 2 s.c om*/
        FileReader fr = new FileReader("/proc/cpuinfo");
        BufferedReader br = new BufferedReader(fr);
        String text = br.readLine();
        String[] array = text.split(":\\s+", 2);

        for (int i = 0; i < array.length; i++) {

        }
        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;//  w  ww . ja va  2 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

static String readerToString(Reader reader) throws IOException {
    StringBuffer stringBuffer = new StringBuffer();
    BufferedReader bufferedReaderA = new BufferedReader(reader);
    String readingString = bufferedReaderA.readLine();
    while (readingString != null) {
        stringBuffer.append(readingString);
        readingString = bufferedReaderA.readLine();
    }/*from w w  w  . ja  v a 2  s. c  om*/
    return stringBuffer.toString();
}

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;//  ww  w .  j  a va  2 s  .co  m
        else
            output.append(line + "\n");
    }
    buff.close();
    return output.toString();
}

From source file:Main.java

private static String readStream(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader r = new BufferedReader(new InputStreamReader(in), 1024);
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        sb.append(line);//from   ww w . ja va 2  s .  co m
    }
    in.close();
    return sb.toString();
}

From source file:Main.java

public static String getAdbPort() throws IOException {
    Process process = Runtime.getRuntime().exec("getprop service.adb.tcp.port");
    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    return reader.readLine();
}

From source file:Main.java

public static String getFromAssets(String fileName, Context context) {
    String line = "";
    String Result = "";
    try {/*from   www .  jav  a2  s .c o m*/
        InputStreamReader inputReader = new InputStreamReader(
                context.getResources().getAssets().open(fileName));
        BufferedReader bufReader = new BufferedReader(inputReader);
        while ((line = bufReader.readLine()) != null)
            Result += line;
        return Result;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return Result;
}

From source file:Main.java

/**
 *
 * @param filename//from w  w w  .jav  a2  s  . c  o m
 */
public static String readTimestampFromFile(String filename) {
    File file = new File(filename);
    try {
        if (file.exists()) {
            BufferedReader br = new BufferedReader(new FileReader(file));
            return br.readLine();
        }
    } catch (Exception e) {
        return null;
    }

    return null;
}