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

static String getSaveLocation(String saveName) {
    String saveLocation;/*w ww . ja  v a2s  .co m*/
    File notification = new File(
            Environment.getExternalStorageDirectory().toString() + "/.Instagram/" + saveName + ".txt");

    try {
        BufferedReader br = new BufferedReader(new FileReader(notification));

        saveLocation = br.readLine();
        saveLocation = saveLocation.replace("file://", "").replaceAll(" ", "%20");
        br.close();
    } catch (Throwable t) {
        saveLocation = "Instagram";
    }

    if (!saveLocation.substring(saveLocation.length() - 1).equals("/") && !saveLocation.equals("Instagram")) {
        saveLocation = saveLocation + "/";
    }

    return saveLocation;
}

From source file:Main.java

public static double[] readVectorDouble(String path) throws FileNotFoundException {
    ArrayList<Double> arr = new ArrayList<Double>();
    System.err.println("Load vector from " + path);
    Scanner sc = new Scanner(new BufferedReader(new FileReader(path)));
    while (sc.hasNext()) {
        String line = sc.nextLine();
        if (line.isEmpty()) {
            break;
        }/*from   w  w  w  . ja v  a2 s  . c om*/
        if (line.startsWith("%%")) { // detect matrix market format
            System.err.println(line);
            while (sc.nextLine().startsWith("%"))
                ; // skip the comment line, and the dimension info.
            continue;
        }
        arr.add(Double.parseDouble(line));
    }
    System.err.println("Length: " + arr.size());
    double[] ret = new double[arr.size()];
    for (int i = 0; i < arr.size(); i++)
        ret[i] = arr.get(i);
    System.err.println("Done.");
    return ret;
}

From source file:Main.java

public static void loadSystemClassPath() {
    try {// w w w. j  ava 2  s.  c om
        File file = new File("../classpath.txt");
        if (!file.exists())
            return;
        BufferedReader bf = new BufferedReader(new FileReader("../classpath.txt"));
        syspath = bf.readLine();
        System.out.println(syspath);
        File pfile = new File(syspath);
        if (!pfile.exists()) {
            bf.close();
            file.delete();
            return;
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

static String getSetting(String name) {
    File file = new File(Environment.getExternalStorageDirectory().toString() + "/.Instagram/" + name + ".txt");
    StringBuilder text = new StringBuilder();

    try {//from   ww w.  java  2 s.  co  m
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
        }
        br.close();
    } catch (IOException e) {
        text.append("Instagram");
    }

    return text.toString();
}

From source file:Main.java

public static int getMinCpuFreq() {
    int result = 0;
    FileReader fr = null;//from  ww  w .  j  a v a2 s .c  om
    BufferedReader br = null;
    try {
        fr = new FileReader(kCpuInfoMinFreqFilePath);
        br = new BufferedReader(fr);
        String text = br.readLine();
        result = Integer.parseInt(text.trim());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fr != null)
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return result;
}

From source file:Main.java

public static int getMaxCpuFreq() {
    int result = 0;
    FileReader fr = null;/*from  w w w  .  j a  v a2  s. c om*/
    BufferedReader br = null;
    try {
        fr = new FileReader(kCpuInfoMaxFreqFilePath);
        br = new BufferedReader(fr);
        String text = br.readLine();
        result = Integer.parseInt(text.trim());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fr != null)
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return result;
}

From source file:Main.java

public static int getCurrCpuFreq() {
    int result = 0;
    FileReader fr = null;//from ww  w .ja  v  a  2  s. c  o  m
    BufferedReader br = null;
    try {
        fr = new FileReader(kCpuInfoCurFreqFilePath);
        br = new BufferedReader(fr);
        String text = br.readLine();
        result = Integer.parseInt(text.trim());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fr != null)
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return result;
}

From source file:Main.java

/**
 * Returns the package name of a file that has one of the annotations we are looking for.
 *
 * @return Package prefix string or null or no annotations.
 *///from   w w  w  .j  av a2 s .  co m
private static String getPackageOfClass(File file) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(file));
    try {
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                return null;
            }
            if (line.contains("package")) {
                String[] parts = line.split("[ \t;]");
                if (parts.length > 1 && parts[0].equals("package")) {
                    return parts[1];
                }
            }
        }
    } finally {
        reader.close();
    }
}

From source file:Main.java

public static void loadXPATHConf() {
    xpath_expression = new String[xpath_size];
    BufferedReader br;//from  www  .j a  v a  2 s .c om
    try {
        br = new BufferedReader(new FileReader(xpathconf_path));

        String line = "";
        int counter = 0;
        while (((line = br.readLine()) != null) && counter < xpath_size) {
            xpath_expression[counter] = line;
            counter++;
        }
        br.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

public static JSONObject readJSONFile(String path) {
    String file = new String(), tmp;
    try {/*  ww w  .j av a 2s. c o m*/
        // Read the file
        BufferedReader bf = new BufferedReader(new FileReader(new File(path)));
        while ((tmp = bf.readLine()) != null) {
            file += tmp;
        }
        bf.close();

        // Parse the JSON
        JSONObject jso = new JSONObject(file);
        return jso;
    } catch (JSONException e) {
        Log.e("JSO reading", "Error parsing the JSO file " + path + "\n" + e.getMessage());
    } catch (IOException e) {
        Log.e("JSO reading", "Error reading the file " + path + "\n" + e.getMessage());
    }

    return null;
}