021.10 IO流 打印流

内容:PrintStream:字节流    PrintWriter:字符流

PrintStream

public static void main(String[] args) throws IOException
{
    //创建对象
    PrintStream ps = new PrintStream("myfile\\print.txt");

    //写入整数
    ps.write(355); //文件里面是c,只是写入整数的最低字节,也就是最后8位二进制
    ps.print(355);  //文件里面是355,写什么就是什么,原理就是把数组转成了字符串

    ps.close();
}

PrintWriter

public static void main(String[] args) throws IOException
{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pw = new PrintWriter(System.out);
    String line = null;
    while((line = br.readLine()) != null){
        if("//over".equals(line)){
            break;
        }
        pw.println(line.toUpperCase());
        pw.flush();
    }
}

//改变目的到文件中,让他自动刷新
pw = new PrintWriter(new BufferedWriter(new FileWriter("myfile\\printwriter.txt")),true);

原文地址:https://www.cnblogs.com/-nbloser/p/9066644.html

时间: 2024-08-30 06:07:55

021.10 IO流 打印流的相关文章

IO【转换流,打印流,序列化】

编码: 把看的懂,变成看不懂的 String str = "中国"; byte[] bytes = str.getBytes(); System.out.println(Arrays.toString(bytes));解码: 把看不懂的内容,变成能看懂的 String s = new String(bytes); System.out.println(s); java.io.OutputStreamWriter extends Writer OutputStreamWriter:转换流

java学习--基础知识进阶第十天--标准输入流 & 转换流 & 打印流、对象操作流 、Properties集合

今日内容介绍 u  标准输入流 & 转换流 & 打印流 u  对象操作流 u  Properties集合 第1章 标准输入流 & 转换流 & 打印流 1.1 标准输入输出流 public static final InputStream in:标准输入流 public static final PrintStream out:标准输出流 package com.itheima_05; /* * 标准输入输出流: public static final InputStream

第1章 标准输入流 & 转换流 & 打印流

1.1 标准输入输出流public static final InputStream in:标准输入流public static final PrintStream out:标准输出流 package com.itheima_05; /* * 标准输入输出流: public static final InputStream in:字节输入流,用来读取键盘录入的数据 public static final int x; InputStream is = System.in; Scanner sc

转换流,打印流,序列化

微信公众号:菜鸟永恒 第11天 IO流今日内容介绍?    转换流?    序列化流?    打印流?    Properties今日学习目标?    能够阐述编码表的意义?    能够使用转换流读取指定编码的文本文件?    能够使用转换流写入指定编码的文本文件?    能够使用Properties的load方法加载文件中配置信息?    能够使用Properties的store方法保存配置信息到文件?    能够说出打印流的特点?    能够使用序列化流写出对象到文件?    能够使用反序列

Java API —— IO流(数据操作流 & 内存操作流 & 打印流 & 标准输入输出流 & 随机访问流 & 合并流 & 序列化流 & Properties & NIO)

1.操作基本数据类型的流 1) 操作基本数据类型 · DataInputStream:数据输入流允许应用程序以与机器无关方式从底层输入流中读取基本 Java 数据类型.应用程序可以使用数据输出流写入稍后由数据输入流读取的数据. · DataOutputStream:数据输出流允许应用程序以适当方式将基本 Java 数据类型写入输出流中.然后,应用程序可以使用数据输入流将数据读入. package datastreamdemos; import java.io.*; /** * Created b

IO流---打印流

package 打印流; import java.io.FileNotFoundException; import java.io.PrintWriter; public class Demo1 { public static void main(String[] args) { PrintWriter pw = null; try { pw = new PrintWriter("c.txt"); pw.print("aaa"); pw.print('c'); pw

IO流之Properties(String键值对)+序列流+打印流+commons-IO(最终流程)

学了这么多全是给他用的之Commons 用这个的前提需要导包, ①创建lib文件夹 ②将下载的commos-io.jar拷贝到lib文件夹 ③右键点击commons-io.jar,Build Path→Add to Build Path 然后介绍两个工具类 1.2 FilenameUtils 这个工具类是用来处理文件名,他可以轻松解决不同操作系统文件名称规范不同的问题 l 常用方法: getExtension(String path):获取文件的扩展名: getName(String filen

JAVA笔记12__字节、字符缓冲流/打印流/对象流/

/** * !!:以后写流的时候一定要加入缓冲!! * 对文件或其它目标频繁的读写操作,效率低,性能差. * 缓冲流:好处是能更高效地读写信息,原理是将数据先缓冲起来,然后一起写入或读取出来. * * BufferedInputStream:字节缓冲流(有一个内部缓冲区数组,用于缓冲数据) */ public class Main { public static void main(String[] args) { input(); output(); } /** * 使用字节缓冲流进行读取操作

字符流+打印流

一.步骤 public class Copy {//打印流+缓冲流 最有效率 public static void main(String[] args) throws IOException { //明确数据源 FileReader f=new FileReader("D:\\java1018\\println.txt"); //添加缓冲流 BufferedReader br=new BufferedReader(f); //明确目的地 FileWriter fw=new FileW