public static void main(String[] args) { try { if (args.length != 1) throw new IllegalArgumentException("Wrong number of arguments"); FileReader in = new FileReader(args[0]); HardcopyWriter out = null; Frame f = new Frame("PrintFile: " + args[0]); f.setSize(200, 50); f.show(); try { out = new HardcopyWriter(f, args[0], 10, .75, .75, .75, .75); } catch (HardcopyWriter.PrintCanceledException e) { System.exit(0); } f.setVisible(false); char[] buffer = new char[4096]; int numchars; while ((numchars = in.read(buffer)) != -1) out.write(buffer, 0, numchars); out.close(); } catch (Exception e) { System.err.println(e); System.err.println("Usage: java HardcopyWriter$PrintFile <filename>"); System.exit(1); } System.exit(0); }
private String readLine(FileReader fileReader) throws IOException { StringBuffer line = new StringBuffer(); int c; while ((c = fileReader.read()) != '\n') { line.append((char) c); } return line.toString(); }
private long getFileLineCount(File file) throws IOException { long count = 0; int c; try (FileReader inputStream = new FileReader(file)) { while ((c = inputStream.read()) != -1) { if (c == '\n') count++; } return count; } }