List of usage examples for java.io FileReader FileReader
public FileReader(FileDescriptor fd)
From source file:org.psidnell.omnifocus.model.RawData.java
public static RawData importRawData(File file) throws IOException { try (Reader in = new FileReader(file)) { return OBJECT_MAPPER.readValue(in, RawData.class); }/*from w w w.ja va 2s.c o m*/ }
From source file:edu.birzeit.cs.parsers.TestParsingWithJSON.java
private static String readFile(String file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(file)); String line = null;/*from ww w . j a v a 2 s .com*/ StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); while ((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(ls); } return stringBuilder.toString(); }
From source file:com.tilab.ca.sse.core.util.SSEUtils.java
public static Set<String> getStopWords(String stopwordsFilePath) throws IOException { LOG.debug("[getStopWords] - BEGIN"); List<String> stopWordsList = new ArrayList<>(); try (BufferedReader bufferedReader = new BufferedReader(new FileReader(stopwordsFilePath))) { String line;//from w w w .j a v a 2 s. c o m while ((line = bufferedReader.readLine()) != null) { stopWordsList.add(line.trim()); } } Set<String> stopwordsSet = new HashSet<>(stopWordsList); LOG.debug("[getStopWords] - END"); return stopwordsSet; }
From source file:Main.java
/** Retrieve list of media sources */ public static boolean ReadUrlInfoToList(List<String> listUrl, String configureFile) { String sUrl, line = ""; sUrl = configureFile;//from w w w . j a va 2s . co m File UrlFile = new File(sUrl); if (!UrlFile.exists()) return false; FileReader fileread; try { fileread = new FileReader(UrlFile); BufferedReader bfr = new BufferedReader(fileread); try { while (line != null) { line = bfr.readLine(); if (line != null) listUrl.add(line); } fileread.close(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } return true; }
From source file:Main.java
private static String readTextFile(String fullPathFilename) throws IOException { StringBuffer contents = new StringBuffer(); BufferedReader reader = null; reader = new BufferedReader(new FileReader(fullPathFilename)); String text = null;//w w w. j a v a 2 s . c o m while ((text = reader.readLine()) != null) { contents.append(text).append(System.getProperty("line.separator")); } reader.close(); return contents.toString(); }
From source file:com.hp.test.framework.Reporting.removerunlinks.java
public static void removelinksforpreRuns(String FilePath, String FileName, int lastrun) throws FileNotFoundException, IOException { log.info("Removing hyper link for the last run"); ArrayList<String> Links_To_Remove = new ArrayList<String>(); for (int i = 1; i < lastrun; i++) { Links_To_Remove.add("href=\"Run_" + i + "\\CurrentRun.html\""); }/*from w ww . j a va 2 s .c om*/ File source = new File(FilePath + FileName); File temp_file = new File(FilePath + "temp.html"); BufferedReader in = new BufferedReader(new FileReader(source)); BufferedWriter out = new BufferedWriter(new FileWriter(temp_file)); String str = ""; while ((str = in.readLine()) != null) { String temp_ar[] = str.split(" "); for (int i = 0; i < temp_ar.length; i++) { String temp = temp_ar[i].trim(); if (!temp.equals("")) { if (Links_To_Remove.contains(temp)) { out.write(" "); out.newLine(); } else { out.write(temp); out.newLine(); } } } } out.close(); in.close(); out = null; in = null; source.delete(); temp_file.renameTo(source); }
From source file:Main.java
public static String[] readN(int n, File file) { String[] buffer = new String[n]; String[] result = null;/*from w w w . j a v a2s .co m*/ int i = 0; try { BufferedReader reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); while (line != null) { if (!line.equals("")) buffer[i++ % n] = line; // if(i >= n) i = 0; line = reader.readLine(); } } catch (IOException e) { // TODO: handle exception } // StringBuffer result = new StringBuffer(); // if(i >= n){ // for(int j = 0; j < n; j++){ // result.append(buffer[ (i + j) % n ]).append("\n"); // } // } // else{ // for(int j = 0; j < i; j++){ // result.append(buffer[j]).append("\n"); // } // } if (i >= n) { result = new String[n]; for (int j = 0; j < n; j++) { result[j] = buffer[(i + j) % n]; } } else { result = new String[i]; for (int j = 0; j < i; j++) { result[j] = buffer[j]; } } return result; }
From source file:Util.java
public static String contentsAsString(File f) throws java.io.IOException { assert (f != null); return contentsAsCharSequence(new BufferedReader(new FileReader(f))).toString(); }
From source file:Main.java
/** * Load a text file contents as a <code>String<code>. * This method does not perform enconding conversions * * @param file The input file//from w ww . j a v a2 s .c o m * @return The file contents as a <code>String</code> * @exception IOException IO Error */ public static String deserializeString(File file) throws IOException { int len; char[] chr = new char[4096]; final StringBuffer buffer = new StringBuffer(); final FileReader reader = new FileReader(file); try { while ((len = reader.read(chr)) > 0) { buffer.append(chr, 0, len); } } finally { reader.close(); } return buffer.toString(); }
From source file:Main.java
/** * Converts the XML file specified into the specified POJO type * @param <T> the object type of the POJO * @param xmlfile the XML file to convert * @param classOfT the class of the POJO * @return the POJO object if conversion was successful * @throws JAXBException/*ww w .jav a 2 s .c o m*/ * @throws XMLStreamException * @throws FileNotFoundException */ public static <T> T convertToPojo(File xmlfile, Class<T> classOfT) throws JAXBException, XMLStreamException, FileNotFoundException { JAXBContext jaxbContext = JAXBContext.newInstance(classOfT); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); XMLInputFactory xif = XMLInputFactory.newFactory(); // settings to prevent xxe // would be funny if this tool is itsef is vulnerable to xxe :D xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader(xmlfile)); T t = (T) jaxbUnmarshaller.unmarshal(xsr);//(xmlfile); return t; }