打印流(PrintWriter )
PrintWriter
package cn.lijun.demo1; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter; // 打印流 PrintStream PrintWriter
// 特点 不负责数据源 只负责数据目的 不会抛IOException 可能会抛出其他异常
public class Demo1PrintWrite {
public static void main(String[] args) throws Exception {
fun4();
}
//打印流可以开启自动刷新功能 输出的数据必须是流对象 Outputem Writer
// 必须调用print 方法
public static void fun4() throws FileNotFoundException{
FileOutputStream fos = new FileOutputStream("c:\\ll.txt");
PrintWriter pr = new PrintWriter(fos,true);
pr.print("zhang");
pr.print("zhang");
pr.print("zhang");
pr.close();
}
//打印流输出目的 是流对象
public static void fun3() throws FileNotFoundException{
PrintWriter p= new PrintWriter("c:\\6.txt");
PrintWriter p1= new PrintWriter(p);
p1.println("打印流");
p1.close(); } //打印流 输出目的 String 文件名
public static void fun2() throws FileNotFoundException{
PrintWriter p = new PrintWriter("c:\\3.txt");
p.println(333);
p.println(333);
p.close();
}
/*向File对象的数据目的写入数据*/
public static void fun() throws Exception{
File file = new File("c:\\2.txt");
PrintWriter p = new PrintWriter(file);
p.print(true);
p.print(100);
p.close();
}
}
//打印流复制文件
package cn.lijun.demo1; import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter; public class Demo2PrintReder {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new FileReader("c:\\ll.txt"));
PrintWriter p= new PrintWriter(new FileWriter("d:\\ll.txt"),true);
String line= null;
while((line=bf.readLine())!=null){
p.print(line);
}
p.close();
bf.close();
}
}
打印流(PrintWriter )的更多相关文章
- JAVA之旅(三十)——打印流PrintWriter,合并流,切割文件并且合并,对象的序列化Serializable,管道流,RandomAccessFile,IO其他类,字符编码
JAVA之旅(三十)--打印流PrintWriter,合并流,切割文件并且合并,对象的序列化Serializable,管道流,RandomAccessFile,IO其他类,字符编码 三十篇了,又是一个 ...
- 打印流PrintWriter
* 打印流 * 字节流打印流 PrintStream * 字符流打印流PrintWriter * * 打印流的特点: * A:只有写数据的,没有读取数据,只能操作目的地,不能操作数据源 * * B:可 ...
- java 21 - 12 IO流的打印流
打印流 字节流打印流 PrintStream 字符打印流 PrintWriter打印流的特点: A:只有写数据的,没有读取数据.只能操作目的地,不能操作数据源.(只能写入数据到文件中,而不能从文件中提 ...
- Java基础知识强化之IO流笔记59:打印流
1. 打印流 (1)分类: • 字节打印流 PrintStream • 字符打印流 PrintWriter (2)打印流的特点: • 只能写数据,不能读数据 • 只能操作目的地,不能操作数据源 ...
- Java IO流之打印流与标准流
一.打印流 1.1打印流特点与构造方法 1)PrintStream和PrintWriter类都提供了一系列重载的print和println方法来输出各种类型的数据. 2)PrintStream和Pri ...
- JavaProperties类、序列化流与反序列化流、打印流、commons-IO整理
Properties类 Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串. 特点: 1.Hashtable的子类 ...
- [Day25]IO(Properties、序列化流、打印流、Commons-IO)
1.Properties类-持久的属性集,可保存在流中或从流中加载,属性列表中每个键及其对应值都是一个字符串 1.1 特点 (1)Hashtable的子类,map集合中的方法都可以用 (2)该集合没有 ...
- Java第三阶段学习(五、流的操作规律、Properties流、序列化流与反序列化流、打印流、commons-IO jar包)
一.流的操作规律 四个明确: 明确一:明确要操作的数据是数据源还是数据目的地 源:InputStream Reader 目的地:OutputStream Writer 先根据需求明确是要读还是写 ...
- 25_IO_第25天(Properties、序列化流、打印流、CommonsIO)_讲义
今日内容介绍 1.Properties集合 2.序列化流与反序列化流 3.打印流 4.commons-IO 01Properties集合的特点 * A: Properties集合的特点 * a: Pr ...
随机推荐
- Ajax与CORS通信
处理跨域的主要方法 JSONP CORS 本文主要讨论CORS解决Ajax因为浏览器同源策略不能跨域请求数据的问题. 1. JSONP JSONP跨域可以参考下面这篇博客 JSONP跨域 2. COR ...
- vuex2.0 基本使用(4) --- modules
vue 使用的是单一状态树对整个应用的状态进行管理,也就是说,应用中的所有状态都放到store中,如果是一个大型应用,状态非常多, store 就会非常庞大,不太好管理.这时vuex 提供了另外一种方 ...
- Easy Finding POJ - 3740 (DLX)
显然这是一道dfs简单题 或许匹配也能做 然而用了dancing links 显然这也是一道模板题 好的吧 调了一上午 终于弄好了模板 Easy Finding Time Limit: 1000MS ...
- kebab HDU - 2883(按时间段建点)
题意: 有n个人去撸串,每个人都能决定自己的串上有几块肉,每一块肉都要花费一个单位时间才熟,烤炉一次能烤m块肉 给出每个人的起始时间.终止时间.要几串.每个串上有几块肉,问能否满足所有的人 (啥?题不 ...
- python学习日记(文件操作练习题)
登录注册(三次机会) name = input('请注册姓名:') password = input('请注册密码:') with open('log',mode='w',encoding='utf- ...
- Nagios 配置自动发邮件功能
安装sendmailyum install -y sendmail* mailx 修改防火墙设置,添加25端口到防火墙vi /etc/sysconfig/iptables 重启 iptables.se ...
- luogu3278/bzoj3323 多项式的运算 (splay)
mulx的操作,其实就是给r+1的系数+=r的系数,然后删掉r,把l~r-1向右移一位,再插一个0到原来的位置 splay维护区间加和区间乘就好了 (一定要注意做事的顺序,一件事都做完了再去做别的,否 ...
- [JSOI2008]魔兽地图(树形dp)
DotR (Defense of the Robots) Allstars是一个风靡全球的魔兽地图,他的规则简单与同样流行的地图DotA (Defense of the Ancients) Allst ...
- Loj 103、10043 (KMP统计子串个数)
KMP算法学习链接:https://blog.csdn.net/starstar1992/article/details/54913261/ KMP算法:可以实现复杂度为O(m+n) 为何简化了时间复 ...
- nodejs的某些api~(一)node的流1
根据心情整理一些node的api~ 今天第一篇,node的流:node的流比较重要,node的流存在于node的各个模块,包括输入输出流,stdin,stout.fs读取流,zlib流,crypto流 ...