IO之Print流举例
import java.io.*;
public class TestPrintStream1 {
public static void main(String[] args) {
PrintStream ps = null;
try {
FileOutputStream fos =
new FileOutputStream("d:\\bak\\log.dat");
ps = new PrintStream(fos);
} catch (IOException e) {
e.printStackTrace();
}
if(ps != null){
System.setOut(ps);
}
int ln = 0;
for(char c = 0; c <= 60000; c++){
System.out.print(c+ " ");
if(ln++ >=100){ System.out.println(); ln = 0;}
}
}
}
import java.io.*;
public class TestPrintStream2 {
public static void main(String[] args) {
String filename = args[0];
if(filename!=null){list(filename,System.out);}
}
public static void list(String f,PrintStream fs){
try {
BufferedReader br =
new BufferedReader(new FileReader(f));
String s = null;
while((s=br.readLine())!=null){
fs.println(s);
}
br.close();
} catch (IOException e) {
fs.println("无法读取文件");
}
}
}
import java.util.*;
import java.io.*;
public class TestPrintStream3 {
public static void main(String[] args) {
String s = null;
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
try {
FileWriter fw = new FileWriter
("d:\\bak\\logfile.log", true); //Log4J
PrintWriter log = new PrintWriter(fw);
while ((s = br.readLine())!=null) {
if(s.equalsIgnoreCase("exit")) break;
System.out.println(s.toUpperCase());
log.println("-----");
log.println(s.toUpperCase());
log.flush();
}
log.println("==="+new Date()+"===");
log.flush();
log.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
IO之Print流举例的更多相关文章
- IO之Object流举例
import java.io.*; public class TestObjectIO { public static void main(String args[]) throws Exceptio ...
- IO之转换流举例
import java.io.*; public class TestTransForm1 { public static void main(String[] args) { try { Outpu ...
- Java中I/O流之Print流
Java 中的 print 流: print 流用于做输出将会非常的方便,并且具有以下特点: 1. printWriter.printStream 都属于输出流,分别针对字符,字节. 2. print ...
- JAVA笔记25-IO流(3)-处理流举例
处理流类型: 1.缓冲流 例1: import java.io.*; public class TestBufferStream{ public static void main(String arg ...
- Java(35)IO特殊操作流&Properties集合
作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15228454.html 博客主页:https://www.cnblogs.com/testero ...
- Java IO 文件与流基础
Java IO 文件与流基础 @author ixenos 摘要:创建文件.文件过滤.流分类.流结构.常见流.文件流.字节数组流(缓冲区) 如何创建一个文件 #当我们调用File类的构造器时,仅仅是在 ...
- Java IO之处理流
一.处理流: 增强功能,提供性能,在节点流之上. 二.节点流与处理流的关系 节点流(字节流.字符流)处于IO操作的第一线,所有操作必须通过它们进行: 处理流可以对其他流进行处理(提高效率或操作灵活性) ...
- Java IO: 其他字符流(下)
作者: Jakob Jenkov 译者: 李璟(jlee381344197@gmail.com) 本小节会简要概括Java IO中的PushbackReader,LineNumberReader,St ...
- 17 IO流(十四)——Print流
PrintStream流 PrintStream作为一个包装流,它可以包装字节流,甚至可以使用指定的文件创建一个打印流.它的构造函数很丰富,建议打开API看一下. 它常用的方法是print方法与pri ...
随机推荐
- jquery 3D云
http://www.jq22.com/jquery-info1325 http://demo.jq22.com/jquery-cloud-141217202931 下载地址: http://www. ...
- ubuntu 怎么格式化U盘?(转载)
转自:http://3168247.blog.51cto.com/3158247/605654 图形的话装一个gparted,找那个/dev/sdb,右击选择格式化,最后点“应用”.命令行:原则是先卸 ...
- java-通过反射获取目标类的属性,方法,构造器
首先定义一个urse package com.studay_fanshe; public class User { private String uname; private int age; pri ...
- 使用python计算softmax函数
softmax计算公式: Softmax是机器学习中一个非常重要的工具,他可以兼容 logistics 算法.可以独立作为机器学习的模型进行建模训练.还可 ...
- 转载:4412环境搭建:arm-linux-gcc: 没有那个文件或目录
4412环境搭建:arm-linux-gcc: 没有那个文件或目录 2014年10月15日 ⁄ 环境搭建 ⁄ 共 993字 ⁄ 字号 小 中 大 ⁄ 评论 11 条 ⁄ 阅读 6,125 次 最近弄了 ...
- php 文件锁flock解决并发
方案一:使用文件锁排它锁 flock函数用于获取文件的锁,这个锁同时只能被一个线程获取到,其它没有获取到锁的线程要么阻塞,要么获取失败 在获取到锁的时候,先查询,如果查询成功则进行操作,然后释放锁 f ...
- 查找MySQL和 SQL sever data
MySql SQL server
- ural1076 Trash 垃圾
Description You were just hired as CEO of the local junkyard.One of your jobs is dealing with the in ...
- [Usaco2006 Jan] Dollar Dayz 奶牛商店
Description 约翰到奶牛商场里买工具.商场里有K(1≤K≤100).种工具,价格分别为1,2,-,K美元.约翰手里有N(1≤N≤1000)美元,必须花完.那他有多少种购买的组合呢? Inpu ...
- linux自动连接校园网设置
不知道有没有人用linux的时候碰到过校园网连接后,跳不出登录界面,即使手动输入也没有作用.写一个可能可行的方法: - 首先打开控制面板 选择网络代理 将代理中的选项设置为 估计现在就能自动弹出登录页 ...