- 浏览: 234223 次
-
文章分类
- 全部博客 (160)
- java语言基础 (67)
- jsp基础 (2)
- eclipse使用 (2)
- java源码解读 (6)
- 计算机基础 (3)
- eclipse插件 (0)
- 网络基础 (8)
- 算法 (2)
- linux (0)
- 英语 (0)
- C语言 (4)
- JavaScript (17)
- 数学 (0)
- struts2 (2)
- 自然哲学 (0)
- Servlet (1)
- HttpServer (2)
- ext (1)
- 个人 (1)
- dojo (27)
- spring (2)
- hibernate (4)
- css (3)
- 多线程 (0)
- chrome插件开发 (0)
- svn (0)
- thrift (2)
- phonegap (1)
- java线程 (1)
- 不是很熟悉的css属性 (0)
- 数据库性能调优 (0)
- 项目管理 (1)
- ios (0)
- 软件工程 (0)
- db2 (0)
- 词汇管理 (0)
- zhenyan (0)
- 计划 (0)
- android (0)
- ssss (0)
- 是的 (0)
- dsada (0)
- 泛点是 (0)
- fds (0)
- cxzc (0)
- 权限 (0)
- dfsfds (0)
- http://www.cnblogs.com/kingboy2008/p/5261771.html (0)
- sss (0)
- ddd (0)
- fdsfdsf (0)
- sso (0)
- nginx (0)
- 分布式数据一致性 (0)
- mysql (0)
- ios永久存储 (0)
- js匿名函数 (0)
- 打印机qqq (0)
最新评论
public class PrintStream extends FilterOutputStream implements Appendable, Closeable { private boolean autoFlush = false; private boolean trouble = false; private Formatter formatter; private BufferedWriter textOut; private OutputStreamWriter charOut; public PrintStream(OutputStream out) { this(out, false); } private PrintStream(boolean autoFlush, OutputStream out) { super(out); if (out == null) throw new NullPointerException("Null output stream"); this.autoFlush = autoFlush; } private void init(OutputStreamWriter osw) { this.charOut = osw; this.textOut = new BufferedWriter(osw); } public PrintStream(OutputStream out, boolean autoFlush) { this(autoFlush, out); init(new OutputStreamWriter(this)); } public PrintStream(OutputStream out, boolean autoFlush, String encoding) throws UnsupportedEncodingException { this(autoFlush, out); init(new OutputStreamWriter(this, encoding)); } public PrintStream(String fileName) throws FileNotFoundException { this(false, new FileOutputStream(fileName)); init(new OutputStreamWriter(this)); } public PrintStream(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException { this(false, new FileOutputStream(fileName)); init(new OutputStreamWriter(this, csn)); } public PrintStream(File file) throws FileNotFoundException { this(false, new FileOutputStream(file)); init(new OutputStreamWriter(this)); } public PrintStream(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException { this(false, new FileOutputStream(file)); init(new OutputStreamWriter(this, csn)); } private void ensureOpen() throws IOException { if (out == null) throw new IOException("Stream closed"); } public void flush() { synchronized (this) { try { ensureOpen(); out.flush(); } catch (IOException x) { trouble = true; } } } private boolean closing = false; /* To avoid recursive closing */ public void close() { synchronized (this) { if (!closing) { closing = true; try { textOut.close(); out.close(); } catch (IOException x) { trouble = true; } textOut = null; charOut = null; out = null; } } } public boolean checkError() { if (out != null) flush(); if (out instanceof java.io.PrintStream) { PrintStream ps = (PrintStream) out; return ps.checkError(); } return trouble; } protected void setError() { trouble = true; } protected void clearError() { trouble = false; } /* * Exception-catching, synchronized output operations, which also implement * the write() methods of OutputStream */ public void write(int b) { try { synchronized (this) { ensureOpen(); out.write(b); if ((b == '\n') && autoFlush) out.flush(); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } } public void write(byte buf[], int off, int len) { try { synchronized (this) { ensureOpen(); out.write(buf, off, len); if (autoFlush) out.flush(); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } } /* * The following private methods on the text- and character-output streams * always flush the stream buffers, so that writes to the underlying byte * stream occur as promptly as with the original PrintStream. */ private void write(char buf[]) { try { synchronized (this) { ensureOpen(); textOut.write(buf); textOut.flushBuffer(); charOut.flushBuffer(); if (autoFlush) { for (int i = 0; i < buf.length; i++) if (buf[i] == '\n') out.flush(); } } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } } private void write(String s) { try { synchronized (this) { ensureOpen(); textOut.write(s); textOut.flushBuffer(); charOut.flushBuffer(); if (autoFlush && (s.indexOf('\n') >= 0)) out.flush(); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } } private void newLine() { try { synchronized (this) { ensureOpen(); textOut.newLine(); textOut.flushBuffer(); charOut.flushBuffer(); if (autoFlush) out.flush(); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } } /* Methods that do not terminate lines */ public void print(boolean b) { write(b ? "true" : "false"); } public void print(char c) { write(String.valueOf(c)); } public void print(int i) { write(String.valueOf(i)); } public void print(long l) { write(String.valueOf(l)); } public void print(float f) { write(String.valueOf(f)); } public void print(double d) { write(String.valueOf(d)); } public void print(char s[]) { write(s); } public void print(String s) { if (s == null) { s = "null"; } write(s); } public void print(Object obj) { write(String.valueOf(obj)); } /* Methods that do terminate lines */ public void println() { newLine(); } public void println(boolean x) { synchronized (this) { print(x); newLine(); } } public void println(char x) { synchronized (this) { print(x); newLine(); } } public void println(int x) { synchronized (this) { print(x); newLine(); } } public void println(long x) { synchronized (this) { print(x); newLine(); } } public void println(float x) { synchronized (this) { print(x); newLine(); } } public void println(double x) { synchronized (this) { print(x); newLine(); } } public void println(char x[]) { synchronized (this) { print(x); newLine(); } } public void println(String x) { synchronized (this) { print(x); newLine(); } } public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } } public PrintStream printf(String format, Object... args) { return format(format, args); } public PrintStream printf(Locale l, String format, Object... args) { return format(l, format, args); } public PrintStream format(String format, Object... args) { try { synchronized (this) { ensureOpen(); if ((formatter == null) || (formatter.locale() != Locale.getDefault())) formatter = new Formatter((Appendable) this); formatter.format(Locale.getDefault(), format, args); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } return this; } public PrintStream format(Locale l, String format, Object... args) { try { synchronized (this) { ensureOpen(); if ((formatter == null) || (formatter.locale() != l)) formatter = new Formatter(this, l); formatter.format(l, format, args); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } return this; } public PrintStream append(CharSequence csq) { if (csq == null) print("null"); else print(csq.toString()); return this; } public PrintStream append(CharSequence csq, int start, int end) { CharSequence cs = (csq == null ? "null" : csq); write(cs.subSequence(start, end).toString()); return this; } public PrintStream append(char c) { print(c); return this; } }
发表评论
-
mysql并发
2013-01-08 13:38 0/** * 测试msql JDBC连接并发安全性 ... -
java注解2
2013-01-06 22:02 1023由前一篇的代码,运行代码如下:public clas ... -
java注解1
2013-01-06 21:56 950本文演示java注解的使用 1. getDe ... -
Java集合框架分析
2012-08-29 21:28 01. Java集合整体框架 下面的两张图说明 ... -
AbstractList
2012-08-29 20:48 983public abstract class Abstra ... -
Set
2012-08-28 11:17 684public interface Set<E> e ... -
List源码
2012-08-28 11:15 1016public interface List<E&g ... -
Collection源码
2012-08-28 11:13 952public interface Collection< ... -
java集合框架
2012-08-28 10:39 0java的集合框架中,主要有3类常用的集合。 -
web的debug
2012-03-29 10:48 0hh -
文件读取
2012-03-10 19:32 0public class Util { publ ... -
HTML元素的访问
2011-11-30 09:31 0有3忠方法可以访问html中的元素。 -
Schema数据类型
2011-11-26 16:34 0Schema不仅内置了丰富的数据类型,而且还允许开发者 ... -
初学XML3
2011-11-26 10:08 0编写了XML Schema语义约束之后,必须将其导入目 ... -
初学XML2
2011-11-26 09:22 822<?xml version="1.0& ... -
初学XML
2011-11-26 08:50 893<?xml version="1.0&q ... -
JavaScript字符串
2011-11-19 21:29 925JavaScript有三种基本数据类型,字符串,数字以 ... -
项目管理
2011-11-05 22:39 0项目管理开始于项目计划阶段,贯穿于整个系统开发生命周期 ... -
项目可行性分析
2011-11-05 21:23 0项目可行性包括三个方面:技术可行性,经济可行性,组织 ... -
系统开发生命周期
2011-11-05 21:16 0系统开发生命周期有四个4个基本阶段: 计划- ...
相关推荐
在Java编程语言中,`PrintStream`, `StringBuilder` 和 `Formatter` 是三个非常重要的类,分别用于不同的输出处理。理解并熟练使用这三个类是提升Java编程能力的关键。 首先,我们来详细了解一下`PrintStream`。它...
PrintStream 是打印输出流,它继承于FilterOutputStream。 PrintStream 是用来装饰其它输出流。它能为其他输出流添加了功能,使它们能够方便地打印各种数据值表示形式。 与其他输出流不同,PrintStream 永远不会抛出...
java 输出流中的PrintStream 和 PrintWriter有什么区别
Java学习笔记--PrintStream分享 PrintStream是一种输出流,能够将Java基本数据类型转换为系统预设编码下的字元,再输出至OutputStream中。在Java I/O流中,PrintStream是OutputStream的子类,主要用于将数据输出至...
"PrintStream和PrintWriter的区别简介" PrintStream和PrintWriter都是Java中的输出流类,都是用于将数据输出到目标设备的类,但是它们之间存在一些关键的区别。 首先,从构造方法上看,PrintStream和PrintWriter的...
浅谈PrintStream和PrintWriter的区别和联系 PrintStream和PrintWriter都是Java中的输出流类,但它们之间存在着一些区别和联系。本篇文章将通过示例代码详细介绍这两者之间的区别和联系,希望能够对大家的学习或者...
Java 中的 PrintStream 介绍 PrintStream 是 Java 中的一种打印输出流,它继承自 FilterOutputStream。PrintStream 的主要功能是装饰其他输出流,使它们能够方便地打印各种数据值表示形式。 PrintStream 的特点是...
PrintStream的用法2---马克-to-win java视频
PrintStream的用法1---马克-to-win java视频的详细描述与介绍
本实验主要介绍了 Java 中的输入输出流,包括 DataInputStream、DataOutputStream、PrintStream 等类的使用,以及对象的序列化和反序列化。通过实验,我们可以掌握流的概念分类、字符串常用操作方法、流的构造和应用...
在Java编程语言中,打印流(PrintStream)是用于输出文本信息的重要类,它属于`java.io`包。本文将深入探讨Java打印流的概念、用途、功能以及如何通过实例进行操作。 **一、打印流的概念** Java PrintStream 类提供...
用法示例# include < PrintStream>void setup () { Serial. begin ( 115200 ); Serial << " Hello, World! " << endl; Serial << F ( " Counting to 0xf in hexadecimal: " ) << hex <&...
PrintStream ps = new PrintStream(s.getOutputStream()); /* 产生发消息的时刻 */ Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); /* 向客户端发消息,消息...
- **PrintStream** 和 **PrintWriter** 都是打印流,它们提供了一系列的 `print` 和 `println` 方法,用于输出基本数据类型的数据,并将其格式化为字符串形式。 - **PrintStream** 和 **PrintWriter** 的输出操作...
### IBM面试题解析 ...- `BufferedOutputStream`、`DataOutputStream` 和 `PrintStream` 都是 `FilterOutputStream` 的子类。 - `FilterOutputStream` 的构造函数通常接受一个 `OutputStream` 作为参数。
对于不同数据类型的数据进行输入输出练习。过程中使用导入Scanner包,Scanner中创建Scanner类型的变量,内容详细易懂,适合Java新手练习
PrintStream printStream = new PrintStream(new FileOutputStream(logFile, true)); printStream.println("[当前时间] [" + logType + "] " + content); printStream.close(); ``` `readLog`方法则需要读取文件中...
PrintStream out = new PrintStream(new FileOutputStream("pc2.estdout")); System.setOut(out); System.out.println("Hello World!"); out.close(); } } ``` 在上面的代码中,我们首先创建了一个 `...
创建一个`PrintStream`实例,传入`FileOutputStream`,并设置其`true`参数,表示追加模式,这样每次保存都不会覆盖原有内容。在`try-catch-finally`块中,分别写入日期和手记内容,最后确保`PrintStream`在完成后被...
import java.io.*; import java.util.Hashtable;...public chat (PrintStream sendmsg,Hashtable chatStream){ this.sendmsg = sendmsg; this.chatStream=chatStream; HttpStatus=new HttpStatusCodes(); }