---
title: "java网络编程之字符流"
author: "chigooo"
date: "2011-04-11T15:56:59Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-04-11T15:56:59Z"
id: 997938
url: "https://chigooo.iteye.com/blog/997938"
---

Java中的流分为两种，一种是字节流（InputStream,OutputStream），另一种是字符流（Reader，Writer）。
在网络程序设计中，如果通信的双方都是Java语言编写的，那么最好使用字符流或者更高级的流类，这是因为使用字符流类提供的编码支持可以避免在使用中文等非ASCII字符时出现乱码。如果通信的另一端的实现是未知的，那么最好使用字节流，并实现通过约定好的通信规则发送和接受数据。
使用字符流可以写出不依赖于具体编码的应用程序，这是因为Java中字符是以Unicode的形式存储的。



If you have too many errors in your program, then all the error messages fly by very quickly. The compiler sends the error messages to the standard error stream, so it's a bit tricky to capture them if they fill more than the window can display.
如果遇到上面的问题，可以在执行的时候加上一个 2>的参数 
javac Text.java 
java Text 2> error.out
可以在文件夹里面得到一个 error.out的文件，里面是错误信息，这样就可以把错误信息重定向到了文件 

如果JAVA没有错误，执行 
javac Text.java 
java Text > text.out


可以把输出重定向到text.out文件里面