List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file, String encoding) throws IOException
From source file:it.cnr.ilc.ilcioutils.IlcIOUtils.java
/** * Read the content from file/* ww w . ja va 2 s . co m*/ * * @param file the file to read from * @return a list of lines */ public static List<String> readFromFile(File file) { List<String> lines = new ArrayList<>(); String message; String encoding = "UTF-8"; try { lines = FileUtils.readLines(file, encoding); } catch (Exception e) { message = String.format("IOException in reading the file %s %s" + file.getName(), e.getMessage()); Logger.getLogger(CLASS_NAME).log(Level.SEVERE, message); } return lines; }
From source file:com.mmone.gpdati.allotment.reader.AllotmentFileReader.java
private void loadData() throws IOException { try {/* ww w . j a va 2s. com*/ Logger.getLogger(AllotmentFileReader.class.getName()).log(Level.INFO, "**** target filename " + fileName); File file = new File(fileName); if (file.exists()) { Logger.getLogger(AllotmentFileReader.class.getName()).log(Level.INFO, "**** file exist " + fileName); lines = FileUtils.readLines(file, "UTF-8"); } else { Logger.getLogger(AllotmentFileReader.class.getName()).log(Level.INFO, "**** file not found " + fileName); throw new IOException("File not found " + fileName); } } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.us.test.H2Helper.java
public static void laodData2H2Db(File ips, String url, String uname, String upasswd) throws IOException, SQLException { List<String> ipsegma = FileUtils.readLines(ips, "GBK"); JdbcConnectionPool cp = JdbcConnectionPool.create(url, uname, upasswd); Connection conn = cp.getConnection(); String sql = "insert into ips values(?,?,?,?,?,?)"; int i = 0;/*from www . j av a2s .c o m*/ for (String ip : ipsegma) { PreparedStatement statement = conn.prepareStatement(sql); String[] ipary = ip.split("\\s+"); if (ipary.length < 2 || ipary[0].indexOf(".") < 0) continue; statement.setString(1, ip2Long(ipary[0].trim())); statement.setString(2, ip2Long(ipary[1].trim())); statement.setString(3, ipary[1].trim()); statement.setString(4, ipary[1].trim()); statement.setString(5, ipary.length <= 2 ? "" : ipary[2].trim()); statement.setString(6, ipary.length <= 3 ? "" : ipary[3].trim()); System.out.println(i++ + ":" + statement.execute()); } conn.close(); cp.dispose(); }
From source file:edu.cuhk.hccl.IDConverter.java
private static void processFile(File inFile, File outFile) throws IOException { List<String> lines = FileUtils.readLines(inFile, "UTF-8"); List<String> buffer = new ArrayList<String>(); for (String line : lines) { String[] cols = line.split("\t"); cols[0] = String.valueOf(mapping.getUserID(cols[0])); cols[1] = String.valueOf(mapping.getItemID(cols[1])); buffer.add(StringUtils.join(cols, '\t')); }// w w w . j a va 2 s .c om Collections.sort(buffer); FileUtils.writeLines(outFile, buffer, false); System.out.printf("ID Converting finished for file: %s.\n", inFile.getAbsolutePath()); }
From source file:fi.otavanopisto.changelogger.Changelogger.java
private static void prependLine(String line, String message) throws IOException, GitAPIException { FileRepositoryBuilder frBuilder = new FileRepositoryBuilder(); Repository repository = frBuilder.setGitDir(new File("./.git")).readEnvironment().build(); Git git = new Git(repository); git.reset().setMode(ResetCommand.ResetType.HARD).call(); git.clean().call();/*from w w w. j ava2s. co m*/ git.fetch().call(); git.pull().call(); File file = new File(CHANGELOG_FILE); List<String> lines = FileUtils.readLines(file, Charsets.UTF_8); lines.add(0, line); FileUtils.writeLines(file, lines); git.commit().setMessage(message).setAuthor("Changelogger", "changelogger@otavanopisto.fi").call(); git.push().call(); }
From source file:jetbrick.tools.chm.reader.JavaInfoReader.java
private List<PackageInfo> getAllPackages(File resource) throws IOException { List<String> lines = FileUtils.readLines(resource, Config.encoding); Map<String, PackageInfo> packageMaps = new HashMap<String, PackageInfo>(32); List<PackageInfo> packages = new ArrayList<PackageInfo>(50); for (String line : lines) { line = line.trim();/*from w w w .j a va 2 s. c o m*/ if (line.length() != 0) { PackageInfo p = new PackageInfo(); p.setName(line); p.setUrl(line.replace('.', '/') + "/package-summary.html"); packageMaps.put(p.getName(), p); packages.add(p); } } // add all classes to package List<ClassInfo> classes = getAllClasses(new File(Config.apiLocation, "allclasses-frame.html")); for (ClassInfo classinfo : classes) { PackageInfo p = packageMaps.get(classinfo.getPackageName()); p.addClass(classinfo); } return packages; }
From source file:io.github.bluemarlin.ui.searchtree.SearchFile.java
public SearchFile(File file) throws IOException { List<String> lines = FileUtils.readLines(file, "UTF-8"); List<String> comments = lines.stream().filter(l -> l.startsWith("`")).collect(Collectors.toList()); renderer = comments.stream().filter(c -> c.contains("$renderer")).findFirst().orElse("default"); if ("default".equals(renderer)) { renderer = BluemarlinConfig.defaultRenderer(); } else {/* w w w . j a va2 s . c om*/ renderer = StringUtils.substringAfter(renderer, "="); } int twentyMinsInMillis = 20 * 60 * 1000; long timeNowInMillis = (new Date()).getTime(); String twentyMinsAgoInMillis = String.valueOf(timeNowInMillis - twentyMinsInMillis); jsonSearch = lines.stream().filter(l -> !l.startsWith("`")) .map(l -> l.replace("$DEFAULT_LEAGUE", BluemarlinConfig.defaultLeague())) .map(l -> l.replace("$TWENTY_MINS_AGO_IN_MILLISEC", twentyMinsAgoInMillis)) .collect(Collectors.joining(System.lineSeparator())); }
From source file:com.microsoft.applicationinsights.extensibility.initializer.docker.internal.DockerContextFactory.java
public DockerContext createDockerContext(File contextFile) throws Exception { String json = FileUtils.readLines(contextFile, "utf-8").get(0); return new DockerContext(json); }
From source file:com.sankalp.characterreader.neuralnetwork.TrainingData.java
private void load() throws IOException { int index;/*from w w w.j ava2 s.c o m*/ List<String> lineList = FileUtils.readLines(outputFile, "UTF-8"); for (index = currentCount; index < (trainingSampleCount - currentCount < THRESHOLD ? trainingSampleCount - currentCount : THRESHOLD) + currentCount; index++) { sampleList.add(index - currentCount, new Sample(new File(trainingDataFolder + "/" + Integer.toString(index) + ".jpg"), Integer.parseInt(lineList.get(index).split(",")[1]))); } sampleIndex = 0; currentCount = index; }
From source file:edu.isistan.carcha.util.PluginUtil.java
/** * Extracts Crosscutting Concerns from a REA file. * * @param iFile the i file//from w w w . j a va2s .co m * @return the Crosscutting Concern list * @throws IOException Signals that an I/O exception has occurred. */ public static List<Entity> concernsFromListFileAsList(IFile iFile) throws IOException { List<Entity> ret = new ArrayList<Entity>(); List<String> documents = FileUtils.readLines(iFile.getRawLocation().makeAbsolute().toFile(), "utf-8"); for (String cStr : documents) { String[] concernStr = cStr.split("\\t", 2); ret.add(new Entity(concernStr[1], concernStr[0], NodeType.CC)); } removeDuplicates(ret); return ret; }