List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:de.mpg.escidoc.util.Util.java
public static String input(String prompt) { String input;/* w w w . ja va 2 s . c o m*/ System.out.println(prompt); Scanner scanner = new Scanner(System.in); input = scanner.nextLine(); return input.trim(); }
From source file:com.doplgangr.secrecy.utils.Util.java
public static Map<String, File> getAllStorageLocations() { Map<String, File> map = new TreeMap<String, File>(); List<String> mMounts = new ArrayList<String>(99); //List<String> mVold = new ArrayList<String>(99); mMounts.add(Environment.getExternalStorageDirectory().getAbsolutePath()); try {//from w w w.j a v a2 s . c o m File mountFile = new File("/proc/mounts"); if (mountFile.exists()) { Scanner scanner = new Scanner(mountFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("/dev/block/vold/")) { String[] lineElements = line.split(" "); String element = lineElements[1]; mMounts.add(element); } } } catch (Exception e) { e.printStackTrace(); } List<String> mountHash = new ArrayList<String>(99); for (String mount : mMounts) { File root = new File(mount); Util.log(mount, "is checked"); Util.log(mount, root.exists(), root.isDirectory(), canWrite(root)); if (canWrite(root)) { Util.log(mount, "is writable"); File[] list = root.listFiles(); String hash = "["; if (list != null) for (File f : list) hash += f.getName().hashCode() + ":" + f.length() + ", "; hash += "]"; if (!mountHash.contains(hash)) { String key = root.getAbsolutePath() + " (" + org.apache.commons.io.FileUtils.byteCountToDisplaySize(root.getUsableSpace()) + " free space)"; mountHash.add(hash); map.put(key, root); } } } mMounts.clear(); return map; }
From source file:bs.ws1.dm.itg.App.java
public static List<String> readFileIntoStringList(String filename) throws FileNotFoundException { List<String> lines = new ArrayList<String>(); Scanner fileScanner = null; fileScanner = new Scanner(new File(filename)); while (fileScanner.hasNextLine()) { lines.add(fileScanner.nextLine()); }//from ww w. j a v a2s. c om return lines; }
From source file:CommandLineInterpreter.java
/** * * * @param file/*from w w w . j ava 2 s.com*/ * @param guiAlert * @return */ public static boolean checkResources(final File file, final boolean guiAlert) { Scanner input = null; String message = null; try { input = new Scanner(file); while (input.hasNextLine()) { String currentFilePath = input.nextLine().trim(); if (!currentFilePath.isEmpty()) { File currentFile = new File(currentFilePath); if (!currentFile.exists() || !currentFile.canRead() || !currentFile.canWrite()) { message = "Can not read/write resource file:\n\"" + currentFile.getAbsolutePath() + "\""; alert(message, guiAlert); return false; } } } } catch (Exception e) { // TODO: logging e.printStackTrace(); } finally { if (input != null) { input.close(); } } return true; }
From source file:org.eclipse.lyo.testsuite.server.trsutils.TestCore.java
/** * This method is used to read the contents * of a file as a String/*from w ww.j av a 2 s .c om*/ * @param f * @return */ protected static String readFileAsString(File f) { StringBuilder stringBuilder = new StringBuilder(); Scanner scanner = null; try { scanner = new Scanner(f); } catch (FileNotFoundException e) { return null; } try { while (scanner.hasNextLine()) { stringBuilder.append(scanner.nextLine() + "\n"); } } finally { scanner.close(); } return stringBuilder.toString(); }
From source file:BitLottoVerify.java
public static Map<String, Long> getPaymentsBlockExplorer(String addr) throws Exception { URL u = new URL("http://blockexplorer.com/address/" + addr); Scanner scan = new Scanner(u.openStream()); TreeMap<String, Long> map = new TreeMap<String, Long>(); while (scan.hasNextLine()) { String line = scan.nextLine(); StringTokenizer stok = new StringTokenizer(line, "\"#"); while (stok.hasMoreTokens()) { String token = stok.nextToken(); if (token.startsWith("/tx/")) { String tx = token.substring(4); line = scan.nextLine();/*from w w w .ja va 2 s. c o m*/ line = scan.nextLine(); StringTokenizer stok2 = new StringTokenizer(line, "<>"); stok2.nextToken(); double amt = Double.parseDouble(stok2.nextToken()); long amt_l = (long) Math.round(amt * 1e8); map.put(tx, amt_l); } } } return map; }
From source file:com.doplgangr.secrecy.Util.java
public static Map<String, java.io.File> getAllStorageLocations() { Map<String, java.io.File> map = new TreeMap<String, File>(); List<String> mMounts = new ArrayList<String>(99); //List<String> mVold = new ArrayList<String>(99); mMounts.add(Environment.getExternalStorageDirectory().getAbsolutePath()); try {/* ww w . j ava2 s .co m*/ java.io.File mountFile = new java.io.File("/proc/mounts"); if (mountFile.exists()) { Scanner scanner = new Scanner(mountFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("/dev/block/vold/")) { String[] lineElements = line.split(" "); String element = lineElements[1]; mMounts.add(element); } } } catch (Exception e) { e.printStackTrace(); } /** try { java.io.File voldFile = new java.io.File("/system/etc/vold.fstab"); if (voldFile.exists()) { Scanner scanner = new Scanner(voldFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("dev_mount")) { String[] lineElements = line.split(" "); String element = lineElements[2]; if (element.contains(":")) element = element.substring(0, element.indexOf(":")); mVold.add(element); } } } catch (Exception e) { e.printStackTrace(); } **/ /* for (int i = 0; i < mMounts.size(); i++) { String mount = mMounts.get(i); if (!mVold.contains(mount)) mMounts.remove(i--); } mVold.clear(); */ List<String> mountHash = new ArrayList<String>(99); for (String mount : mMounts) { java.io.File root = new java.io.File(mount); Util.log(mount, "is checked"); Util.log(mount, root.exists(), root.isDirectory(), canWrite(root)); if (canWrite(root)) { Util.log(mount, "is writable"); java.io.File[] list = root.listFiles(); String hash = "["; if (list != null) for (java.io.File f : list) hash += f.getName().hashCode() + ":" + f.length() + ", "; hash += "]"; if (!mountHash.contains(hash)) { String key = root.getAbsolutePath() + " (" + org.apache.commons.io.FileUtils.byteCountToDisplaySize(root.getUsableSpace()) + " free space)"; mountHash.add(hash); map.put(key, root); } } } mMounts.clear(); return map; }
From source file:io.github.mikesaelim.arxivoaiharvester.CommandLineInterface.java
/** * Construct a "ListRecords" request from user inputs. */// w ww . j a va2 s. co m private static ListRecordsRequest constructListRecordsRequest(Scanner scanner) { while (true) { System.out.println("From date? (in yyyy-mm-dd format; leave it blank for none)"); String fromDate = scanner.nextLine().trim(); System.out.println("Until date? (in yyyy-mm-dd format; leave it blank for none)"); String untilDate = scanner.nextLine().trim(); System.out.println("Set restriction? (leave it blank for none)"); String setSpec = scanner.nextLine().trim(); try { return new ListRecordsRequest(isBlank(fromDate) ? null : LocalDate.parse(fromDate), isBlank(untilDate) ? null : LocalDate.parse(untilDate), isBlank(setSpec) ? null : setSpec); } catch (DateTimeParseException e) { System.out.println(" Sorry, one of the dates was not a valid date string. Try again?"); } catch (URISyntaxException e) { System.out.println("Sorry, the inputs did not result in a valid request URI. Try again?"); } } }
From source file:org.lightcouch.CouchDbUtil.java
public static String readFile(String path) { InputStream instream = CouchDbUtil.class.getResourceAsStream(path); StringBuilder content = new StringBuilder(); Scanner scanner = null; try {/*w ww. ja v a2 s . c o m*/ scanner = new Scanner(instream); while (scanner.hasNextLine()) { content.append(scanner.nextLine() + LINE_SEP); } } finally { scanner.close(); } return content.toString(); }
From source file:de.rub.syssec.saaf.analysis.steps.hash.SSDeep.java
protected static String calculateFuzzyHash(File f) throws IOException { String hash = null;// w ww . j a va 2s .c o m if (SSDEEP_PATH != null) { ProcessBuilder pb = new ProcessBuilder(SSDEEP_PATH, f.getAbsolutePath()); Process proc; Scanner in = null; try { proc = pb.start(); // Start reading from the program in = new Scanner(proc.getInputStream()); while (in.hasNextLine()) { hash = in.nextLine(); } if (hash != null) return hash.substring(0, hash.lastIndexOf(",")); } finally { try { if (in != null) in.close(); } catch (Exception ignored) { } } } else { LOGGER.warn("exec_ssdeep could not be found in saaf.conf"); } return ""; }