Example usage for java.io FileReader FileReader

List of usage examples for java.io FileReader FileReader

Introduction

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

Prototype

public FileReader(FileDescriptor fd) 

Source Link

Document

Creates a new FileReader , given the FileDescriptor to read, using the platform's java.nio.charset.Charset#defaultCharset() default charset .

Usage

From source file:Main.java

public static String getCPUInfo() {
    try {/* ww w  .j  a  v a  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);
        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 getCpuName() {
    try {//from  ww w  . j  a v  a 2s .  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

public static String readFile(String filename) {
    StringBuilder buf = new StringBuilder();
    try {/* w  w w .  j a  va2 s .c om*/
        BufferedReader input = new BufferedReader(new FileReader(filename));
        String line;

        while ((line = input.readLine()) != null) {
            buf.append(line);
            buf.append(System.getProperty("line.separator"));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return buf.toString();
}

From source file:Main.java

public static String readFileAsString(File inputFile) throws IOException {
    String finalResult = "";
    String str;/*w  w w. jav  a 2  s  .  c om*/
    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 GetIniValue(String filename, String variable) {
    try {//ww  w . j  a v a  2  s.c  om
        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 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  .  ja 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

public static String readFileToString(String fullPath) throws Exception {
    File file = new File(fullPath);
    BufferedReader bufRead = new BufferedReader(new FileReader(file));
    StringBuffer strBuf = new StringBuffer();
    String readString = null;/* w  w w.  ja v a  2s.  c o m*/
    String readLine = null;
    while ((readLine = bufRead.readLine()) != null) {
        strBuf.append(readLine);
    }
    readString = strBuf.toString();
    return readString;

}

From source file:Main.java

public static String readFile(String filename) {
    String content = null;//from  w ww.  j  av a 2s . c  o  m
    File file = new File(filename); //for ex foo.txt
    try {
        FileReader reader = new FileReader(file);
        char[] chars = new char[(int) file.length()];
        reader.read(chars);
        content = new String(chars);
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return content;
}

From source file:Main.java

public static String[] GetMountLine(String PartitionName) {
    try {/*from  ww w  .  j  a  va 2 s  .com*/
        BufferedReader bProcFS = new BufferedReader(new FileReader("/proc/mounts"));
        String readLine = null;
        while ((readLine = bProcFS.readLine()) != null) {
            String[] args = readLine.split(" ");
            if ((args.length > 3) && (args[1].equalsIgnoreCase("/" + PartitionName))) {
                return args;
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String readFile(File file) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String line = null;//from ww  w.java2s  .com
    StringBuilder stringBuilder = new StringBuilder();
    String ls = System.getProperty("line.separator");

    while ((line = reader.readLine()) != null) {
        stringBuilder.append(line);
        stringBuilder.append(ls);
    }
    reader.close();
    return stringBuilder.toString();
}