PrintWriter : PrintWriter « File « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » File » PrintWriter 
11.34.1.PrintWriterPrevious/Next
  1. PrintWriter is a better alternative to OutputStreamWriter and FileWriter.
  2. PrintWriter allows you to choose an encoding by passing the encoding information to one of its constructors.
public PrintWriter (File file)
public PrintWriter (File file, String characterSet)
public PrintWriter (String filepath)
public PrintWriter (String filepath, String ccharacterSet)
public PrintWriter (OutputStream out)
public PrintWriter (Writer out)

It is easier to construct a PrintWriter than an OutputStreamWriter.

OutputStreamWriter writer = new OutputStreamWriter new FileOutputStream (filePath), encoding);

can be replaced by this shorter one.

PrintWriter writer = new PrintWriter (filePath, encoding);
11.34.PrintWriter
11.34.1.PrintWriter
11.34.2.PrintWriter is more convenient to work with than OutputStreamWriter
11.34.3.Write lines of text to file using a PrintWriter
11.34.4.Using PrintWriter
11.34.5.A PrintWriter that ends lines with a carriage return-line feed (CRLF).
11.34.6.A PrintWriter that also sends its output to a log stream
11.34.7.Turn System.out into a PrintWriter.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.