List of usage examples for java.io FileReader FileReader
public FileReader(FileDescriptor fd)
From source file:io.ecarf.core.utils.Utils.java
public static void main(String[] args) throws JsonIOException, JsonSyntaxException, FileNotFoundException { Set<String> schemaTerms = Utils.GSON.fromJson( new JsonReader(new FileReader(Utils.TEMP_FOLDER + "test.json")), new TypeToken<Set<String>>() { }.getType());//from w w w .j a va 2s. co m System.out.println(schemaTerms); }
From source file:Main.java
public static char[] getChars(File file) throws IOException { String str;/*from ww w. j a v a2s . co m*/ FileReader reader = new FileReader(file); BufferedReader buffer = new BufferedReader(reader); String line; StringBuilder result = new StringBuilder(); while ((line = buffer.readLine()) != null) { result.append(line).append("\n"); } str = result.toString(); buffer.close(); reader.close(); return str.toCharArray(); }
From source file:Main.java
public static long totalMemorySize() { String memInfoPath = "/proc/meminfo"; String str2;//from ww w. j a va 2 s .c o m String[] arrayOfString; long initial_memory = 0; try { FileReader localFileReader = new FileReader(memInfoPath); BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192); str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); for (String num : arrayOfString) { Log.i(str2, num + "\t"); } //total Memory initial_memory = Integer.valueOf(arrayOfString[1]) * 1024; localBufferedReader.close(); return initial_memory; } catch (IOException e) { return -1; } }
From source file:latexstudio.editor.files.FileService.java
public static String readFromFile(String filename) { try (FileReader reader = new FileReader(filename)) { return IOUtils.toString(reader); } catch (IOException ex) { Exceptions.printStackTrace(ex);//from w ww . ja v a 2 s. co m } return null; }
From source file:Main.java
/** * Convenient call to load a properties file from the provided file *///from w w w. java 2s .c om public static Properties loadProperties(File file) throws IOException { if (file == null) return null; FileReader reader = new FileReader(file); try { return loadProperties(reader); } finally { reader.close(); } }
From source file:Main.java
public static String getStringFromFile(String filePath) { String s = null;/*from www . j av a2s . co m*/ File f = new File(filePath); Reader reader = null; try { reader = new BufferedReader(new FileReader(f)); StringBuilder sb = new StringBuilder(); char[] buff = new char[50]; int length; while ((length = reader.read(buff)) != -1) { sb.append(buff, 0, length); } s = sb.toString(); } catch (FileNotFoundException e) { s = null; } catch (IOException e) { e.printStackTrace(); } return s; }
From source file:com.nomsic.randb.test.TestUtils.java
public static String getFileAsString(File file) throws FileNotFoundException, IOException { FileReader fileReader = new FileReader(file); String indexString = IOUtils.toString(fileReader); fileReader.close();/*ww w.j a v a 2 s. co m*/ return indexString; }
From source file:Main.java
/** * Read file and gives file content as String * * @param filename String/*ww w .j av a2s . c o m*/ * @return String * @throws IOException if unable to read file */ public static String readFile(String filename) throws IOException { return readReader(new FileReader(filename)); }
From source file:Main.java
public static long getRunningProcess() { File file = new File("/proc/meminfo"); BufferedReader bufferedReader = null; String total = null;//from www . j a v a 2 s . com try { bufferedReader = new BufferedReader(new FileReader(file)); String line = bufferedReader.readLine(); char[] charArray = line.toCharArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < charArray.length; i++) { char c = charArray[i]; if (c >= '0' && c <= '9') { sb.append(c); } } total = sb.toString(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } long number = Long.parseLong(total) * 1024; return number; }
From source file:asciidoc.maven.plugin.tools.FileHelper.java
public static String readFile(File f) { StringBuilder contents = new StringBuilder(); try {/*www.j a v a2 s. c o m*/ BufferedReader input = new BufferedReader(new FileReader(f)); try { String line = null; while ((line = input.readLine()) != null) { contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException ex) { ex.printStackTrace(); } return contents.toString(); }