@Test @Ignore public void testReadFromFile() throws Exception { String contents = Utils.readFromFile(Paths.get(UtilsTest.class.getClassLoader().getResource("barcodes.txt").toURI())); String[] strings = Utils.extractBarcodes(contents); for (String string : strings) { System.out.println("contents = " + string); } }
public static String readFromFile(Path path) { try (FileInputStream stream = new FileInputStream(path.toFile())) { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return Charset.defaultCharset().decode(bb).toString(); } catch (IOException e) { e.printStackTrace(); } return ""; }
Utils { public static String readFromFile(Path path) { try (FileInputStream stream = new FileInputStream(path.toFile())) { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return Charset.defaultCharset().decode(bb).toString(); } catch (IOException e) { e.printStackTrace(); } return ""; } }
Utils { public static String readFromFile(Path path) { try (FileInputStream stream = new FileInputStream(path.toFile())) { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return Charset.defaultCharset().decode(bb).toString(); } catch (IOException e) { e.printStackTrace(); } return ""; }  }
Utils { public static String readFromFile(Path path) { try (FileInputStream stream = new FileInputStream(path.toFile())) { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return Charset.defaultCharset().decode(bb).toString(); } catch (IOException e) { e.printStackTrace(); } return ""; }  static int[] getColumnWidth(JTable table); static void initializeTableColumns(JTable table, int size[]); static void save(Class<T> clazz, T obj, String fileName); static T load(Class<T> clazz, String fileName); static Map<String, String> getUrlParameters(String url); static void deleteDir(String path, final LogWindow logWindow); static void writeToFile(String log, Path path); static String readFromFile(Path path); static String getException(Throwable t); static String[] extractBarcodes(String contents); static void listSystemProperties(PrintWriter pw); static boolean pingUrl(final String address, LogWindow logWindow); static String clean(String value); static String removeDuplicateWords(String input); static int tryGetFileSize(URL url); static String readContent(InputStream inputStream); static boolean checkNotNull(String attr); }
Utils { public static String readFromFile(Path path) { try (FileInputStream stream = new FileInputStream(path.toFile())) { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return Charset.defaultCharset().decode(bb).toString(); } catch (IOException e) { e.printStackTrace(); } return ""; }  static int[] getColumnWidth(JTable table); static void initializeTableColumns(JTable table, int size[]); static void save(Class<T> clazz, T obj, String fileName); static T load(Class<T> clazz, String fileName); static Map<String, String> getUrlParameters(String url); static void deleteDir(String path, final LogWindow logWindow); static void writeToFile(String log, Path path); static String readFromFile(Path path); static String getException(Throwable t); static String[] extractBarcodes(String contents); static void listSystemProperties(PrintWriter pw); static boolean pingUrl(final String address, LogWindow logWindow); static String clean(String value); static String removeDuplicateWords(String input); static int tryGetFileSize(URL url); static String readContent(InputStream inputStream); static boolean checkNotNull(String attr);  }