List of usage examples for java.io FileReader FileReader
public FileReader(FileDescriptor fd)
From source file:SMTPDemo.java
public static void main(String args[]) throws IOException, UnknownHostException { String msgFile = "file.txt"; String from = "java2s@java2s.com"; String to = "yourEmail@yourServer.com"; String mailHost = "yourHost"; SMTP mail = new SMTP(mailHost); if (mail != null) { if (mail.send(new FileReader(msgFile), from, to)) { System.out.println("Mail sent."); } else {//ww w . ja v a 2 s . c o m System.out.println("Connect to SMTP server failed!"); } } System.out.println("Done."); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();/*from w w w. ja v a 2 s. c o m*/ PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); BufferedReader reader = new BufferedReader(new FileReader("a.txt")); String line; while ((line = reader.readLine()) != null) { ct.addText(new Phrase(line + "\n")); } reader.close(); ct.setSimpleColumn(36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36, 18, Element.ALIGN_JUSTIFIED); int status = ColumnText.START_COLUMN; while (ColumnText.hasMoreText(status)) { status = ct.go(); ct.setYLine(PageSize.A4.height() - 36); document.newPage(); } document.close(); }
From source file:com.ctt.client.Client.java
public static void main(String[] args) throws Exception { Client.prop = new Properties(); FileReader reader = new FileReader("../config.properties"); Client.prop.load(reader);/* ww w. ja va 2s .com*/ String directory = Client.prop.getProperty("directory"); FilesMonitor listener = new FilesMonitor(); File folder = new File(directory); try { FileAlterationObserver observer = new FileAlterationObserver(directory); FileAlterationMonitor monitor = new FileAlterationMonitor(1000); observer.addListener(listener); monitor.addObserver(observer); monitor.start(); } catch (Exception io) { } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();//w w w .j a v a2 s .co m PdfContentByte cb = writer.getDirectContent(); StringBuffer sb = new StringBuffer(1024); BufferedReader reader = new BufferedReader(new FileReader("a.txt")); int c; while ((c = reader.read()) > -1) { sb.append((char) c); } reader.close(); ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(new Phrase(sb.toString()), 36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36, 18, Element.ALIGN_JUSTIFIED); int status = ColumnText.START_COLUMN; while (ColumnText.hasMoreText(status)) { status = ct.go(); ct.setYLine(PageSize.A4.height() - 36); document.newPage(); } document.close(); }
From source file:json.ReadFromFile.java
public static void main(String[] args) { JSONParser parser = new JSONParser(); try {/*from w w w . j a va 2s . c o m*/ Object obj = parser.parse(new FileReader(file)); JSONObject jsonObject = (JSONObject) obj; String countryName = jsonObject.get("Name") + "";//equivalent to jsonObject.get("Name").toString(); System.out.println("Name of Country: " + countryName); long population = (long) jsonObject.get("Population"); System.out.println("Population: " + population); System.out.println("Counties are:"); JSONArray listOfCounties = (JSONArray) jsonObject.get("Counties"); Iterator<String> iterator = listOfCounties.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } catch (IOException | ParseException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("create table survey (id int, name BINARY);"); String sql = "INSERT INTO survey (name) VALUES(?)"; PreparedStatement pstmt = conn.prepareStatement(sql); File file = new File("yourFileName.txt"); long fileLength = file.length(); Reader fileReader = (Reader) new BufferedReader(new FileReader(file)); pstmt.setCharacterStream(1, fileReader, (int) fileLength); int rowCount = pstmt.executeUpdate(); ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); while (rs.next()) { System.out.println(rs.getBytes(2)); }/*w w w . ja va 2s. c o m*/ rs.close(); stmt.close(); conn.close(); }
From source file:MyTest.ParseJson.java
public static void main(String args[]) { try {/*from w w w . ja v a 2s.c o m*/ FileReader reader = new FileReader( new File("data/NGS___RNA-seq_differential_expression_analysis-v1.ga")); System.out.println(reader); JSONParser parser = new JSONParser(); JSONObject jo = (JSONObject) parser.parse(reader); JSONObject jsteps = (JSONObject) jo.get("steps"); System.out.println(jsteps.size()); System.out.println("---------------------------------------------------"); for (int i = 0; i < jsteps.size(); i++) { JSONObject jstep_detail = (JSONObject) jsteps.get(String.valueOf(i)); getDetailInfo(jstep_detail); } } catch (FileNotFoundException ex) { Logger.getLogger(ParseJson.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ParseJson.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(ParseJson.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace("s", "uri:test:schedule"); xPath.setNamespaceContext(nsContext); String result = xPath.evaluate("/s:schedule/@name", new InputSource(new FileReader("t.xml"))); System.out.println(result);//w ww .j a va 2 s . c o m }
From source file:LowerCaseReader.java
public static void main(String[] args) throws Exception { String fileName = "test.txt"; LowerCaseReader lcr = new LowerCaseReader(new FileReader(fileName)); int c = -1;//from w w w . ja va 2 s. c o m while ((c = lcr.read()) != -1) { System.out.print((char) c); } lcr.close(); BufferedReader br = new BufferedReader(new LowerCaseReader(new FileReader(fileName))); String str = null; while ((str = br.readLine()) != null) { System.out.println(str); } br.close(); }
From source file:com.ctt.sshlistener.Main.java
public static void main(String[] args) throws Exception { Main.prop = new Properties(); FileReader reader = new FileReader("../config.properties"); Main.prop.load(reader);//from w w w . java 2 s .c o m String directory = Main.prop.getProperty("directory"); FilesMonitor listener = new FilesMonitor(); File folder = new File(directory); try { FileAlterationObserver observer = new FileAlterationObserver(directory); FileAlterationMonitor monitor = new FileAlterationMonitor(10000); observer.addListener(listener); monitor.addObserver(observer); monitor.start(); } catch (Exception io) { } }