List of usage examples for java.io FileReader FileReader
public FileReader(FileDescriptor fd)
From source file:com.chargebee.MethodBank.MethodBank.java
public static CSVParser parserInitializer(String csvInput) throws IOException, Exception { CSVParser parser = new CSVParser(new FileReader(csvInput), CSVFormat.EXCEL); return parser; }
From source file:au.edu.unsw.cse.soc.federatedcloud.community.driven.cloudbase.util.LinkedObjectModelFactory.java
public static JSONObject generateObjectFromFile(File file) throws IOException, ParseException { JSONParser parser = new JSONParser(); JSONObject jsonObject = null;// w w w.j av a2 s . c o m jsonObject = (JSONObject) parser.parse(new FileReader(file)); return jsonObject; }
From source file:Main.java
public static String fileContent(File file) throws IOException { String content = ""; BufferedReader reader = new BufferedReader(new FileReader(file)); String line;/*w ww .j ava 2 s . c o m*/ while ((line = reader.readLine()) != null) { content += line; } return content; }
From source file:JSONUtil.java
/** * @param string//from ww w . j av a 2 s .c om * @return * @throws IOException * @throws JSONException */ public static JSONObject loadJson(String file) throws IOException, JSONException { File f = new File(file); FileReader fr = new FileReader(f); JSONTokener j = new JSONTokener(fr); JSONObject in = new JSONObject(j); fr.close(); return in; }
From source file:edu.caltech.ipac.firefly.server.util.DsvToDataGroup.java
public static DataGroup parse(File inf, CSVFormat format) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(inf), IpacTableUtil.FILE_IO_BUFFER_SIZE); List<DataType> columns = new ArrayList<DataType>(); CSVParser parser = new CSVParser(reader, format); List<CSVRecord> records = parser.getRecords(); if (records != null && records.size() > 0) { // parse the column info CSVRecord cols = records.get(0); for (Iterator<String> itr = cols.iterator(); itr.hasNext();) { String s = itr.next(); if (!StringUtils.isEmpty(s)) { columns.add(new DataType(s, null)); // unknown type }/*w w w . ja va 2s . com*/ } DataGroup dg = new DataGroup(null, columns); // parse the data for (int i = 1; i < records.size(); i++) { DataObject row = parseRow(dg, records.get(i)); if (row != null) { dg.add(row); } } dg.shrinkToFitData(); return dg; } return null; }
From source file:at.ac.tuwien.dsg.cloudlyra.utils.IOUtils.java
public static String readData(String fileName) { String tomcatTempFolder = System.getProperty("java.io.tmpdir"); //String tomcatTempFolder="/Volumes/DATA/BigData"; fileName = tomcatTempFolder + "/" + fileName; String data = ""; try {// ww w .ja va2 s .co m BufferedReader br = new BufferedReader(new FileReader(fileName)); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } data = sb.toString(); br.close(); } catch (Exception e) { } return data; }
From source file:importer.handler.post.stages.Splitter.java
/** test and commandline utility */ public static void main(String[] args) { if (args.length >= 1) { try {/* w ww.ja v a2 s. c o m*/ int i = 0; int fileIndex = 0; // see if the user supplied a conf file String textConf = Discriminator.defaultConf; while (i < args.length) { if (args[i].equals("-c") && i < args.length - 1) { textConf = readConfig(args[i + 1]); i += 2; } else { fileIndex = i; i++; } } File f = new File(args[fileIndex]); char[] data = new char[(int) f.length()]; FileReader fr = new FileReader(f); fr.read(data); JSONObject config = (JSONObject) JSONValue.parse(textConf); Splitter split = new Splitter(config); Map<String, String> map = split.split(new String(data)); Set<String> keys = map.keySet(); String rawFileName = args[fileIndex]; int pos = rawFileName.lastIndexOf("."); if (pos != -1) rawFileName = rawFileName.substring(0, pos); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); String fName = rawFileName + "-" + key + ".xml"; File g = new File(fName); if (g.exists()) g.delete(); FileOutputStream fos = new FileOutputStream(g); fos.write(map.get(key).getBytes("UTF-8")); fos.close(); } } catch (Exception e) { e.printStackTrace(System.out); } } else System.out.println("usage: java -jar split.jar [-c json-config] <tei-xml>\n"); }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.report.ConfusionMatrixTools.java
public static ConfusionMatrix tokenLevelPredictionsToConfusionMatrix(File predictionsFile) throws IOException { ConfusionMatrix cm = new ConfusionMatrix(); CSVParser csvParser = new CSVParser(new FileReader(predictionsFile), CSVFormat.DEFAULT.withCommentMarker('#')); for (CSVRecord csvRecord : csvParser) { // update confusion matrix cm.increaseValue(csvRecord.get(0), csvRecord.get(1)); }//from ww w .j a v a 2 s . c o m return cm; }
From source file:com.itbeyond.common.EOTrackMe.java
public static int getLogFileLines() { try {//from w ww .j a v a 2 s . c o m BufferedReader br = new BufferedReader(new FileReader(getLogFile()), 8192); int lineCount = 0; while ((br.readLine()) != null) { lineCount++; } br.close(); return lineCount; } catch (IOException e) { } return 0; }