史上最全IO框架六(打印流)
来源:互联网 发布:centos ffmpeg安装 编辑:程序博客网 时间:2024/06/16 10:00
package com.itheima.filedemo;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* 打印流:(往文件里写东西)
* 关于\r和\n和Enter三者之间的区别
* 1、\r:表示回车,使光标移动到本行的首行
* 2、\n:表示换行,使光标下移一格,
* 3、Enter=\r\n:表示不仅换行而且还要使光标移动到行首,
* @author Administrator
*
*/
public class PrintStreamDemo {
public static void main(String[] args) { // TODO Auto-generated method stub print1(); System.out.println("sucess");}/** * 使用字节打印流(往文件里面写内容) */public static void print1(){ try { //构造一个字节流对象 OutputStream out = new FileOutputStream("E:\\1.txt"); //根据字节流对象构造一个缓冲流对象 BufferedOutputStream bos = new BufferedOutputStream(out); //根据缓冲流对象构造一个打印流对象 PrintStream ps = new PrintStream(bos); //输出(往文件里写东西) ps.println(3.14f); ps.println(188); ps.println(true); ps.println("广东一学校限制女生内衣颜色:豹纹扣3分 蕾丝扣2分"); //关闭流 ps.flush(); bos.close(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }}/** * 使用字符打印流 */public static void print2(){ try { BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\1.txt")); PrintWriter pw = new PrintWriter(bw); pw.println("\r\n");//输出回车加换行符 pw.println(105); pw.println("小米饥饿营销最后别“饿”成笑话"); pw.flush(); pw.close(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }}
}
0 0
- 史上最全IO框架六(打印流)
- 史上最全IO框架二(字节流)
- 史上最全IO框架四(转换流)
- 史上最全IO框架五(缓冲流)
- 【IO流】IO框架
- io(六)其他流常用流
- JAVA菜鸟(六)IO流
- 黑马程序员(六)IO流
- IO总结(六)
- IO流--打印流
- IO流 打印流
- IO流--打印流
- IO学习(十五)PrintStream打印流
- IO之打印流
- IO-07打印流
- IO/打印流
- IO打印流基础知识
- IO-打印流
- 计算机网络 (学习笔记)
- POJ-1000
- Linux 下 查看以及修改文件权限
- 学习笔记-斯坦福iOS7-第十七课:摄像头、Core Motion、Application Stat
- 中国联通沃云----弹性云主机使用说明
- 史上最全IO框架六(打印流)
- leetcode_c++:链表:Odd Even Linked List(328)
- Oracle学习2
- Django URL传递参数的方法总结(转)
- IOS中设置navigationItem的leftBarButtonItem或rightBarButtonItem与边界距离
- 实现Static Initialization从而不需要安装OpenCV Manager
- Android7(N)开发者应该知道的一切(最全)
- maven配置文件详解
- Windows svn服务端安装步骤visualSVN