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流举例的更多相关文章

  1. IO之Object流举例

    import java.io.*; public class TestObjectIO { public static void main(String args[]) throws Exceptio ...

  2. IO之转换流举例

    import java.io.*; public class TestTransForm1 { public static void main(String[] args) { try { Outpu ...

  3. Java中I/O流之Print流

    Java 中的 print 流: print 流用于做输出将会非常的方便,并且具有以下特点: 1. printWriter.printStream 都属于输出流,分别针对字符,字节. 2. print ...

  4. JAVA笔记25-IO流(3)-处理流举例

    处理流类型: 1.缓冲流 例1: import java.io.*; public class TestBufferStream{ public static void main(String arg ...

  5. Java(35)IO特殊操作流&Properties集合

    作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15228454.html 博客主页:https://www.cnblogs.com/testero ...

  6. Java IO 文件与流基础

    Java IO 文件与流基础 @author ixenos 摘要:创建文件.文件过滤.流分类.流结构.常见流.文件流.字节数组流(缓冲区) 如何创建一个文件 #当我们调用File类的构造器时,仅仅是在 ...

  7. Java IO之处理流

    一.处理流: 增强功能,提供性能,在节点流之上. 二.节点流与处理流的关系 节点流(字节流.字符流)处于IO操作的第一线,所有操作必须通过它们进行: 处理流可以对其他流进行处理(提高效率或操作灵活性) ...

  8. Java IO: 其他字符流(下)

    作者: Jakob Jenkov 译者: 李璟(jlee381344197@gmail.com) 本小节会简要概括Java IO中的PushbackReader,LineNumberReader,St ...

  9. 17 IO流(十四)——Print流

    PrintStream流 PrintStream作为一个包装流,它可以包装字节流,甚至可以使用指定的文件创建一个打印流.它的构造函数很丰富,建议打开API看一下. 它常用的方法是print方法与pri ...

随机推荐

  1. (转)C#中数组、ArrayList和List三者的区别

    原文地址:http://blog.csdn.net/zhang_xinxiu/article/details/8657431 在C#中数组,ArrayList,List都能够存储一组对象,那么这三者到 ...

  2. Gym 100531A Alarm Clock (水题)

    题意:给定一个被高亮的数,问你是不是有个时间恰好高亮是这个数. 析:直接暴力,直接暴力,枚举每一位时间,当然也可以枚举时间,能找到就是有,找不到就算了. 代码如下: #pragma comment(l ...

  3. bzoj 4720: [Noip2016]换教室【期望dp】

    状压dp,设f[i][j][0/1]为前i个时间段换了j间教室的期望体力消耗,转移很好想(但是写起来好长= =) #include<iostream> #include<cstdio ...

  4. bzoj 4037: [HAOI2015]数字串拆分【dp+矩阵加速】

    首先f长得就很像能矩阵优化的,先构造转移矩阵(这里有一点神奇的地方,我看网上的blog和我构造的矩阵完全不一样还以为我的构造能力又丧失了,后来惊奇的发现我把那篇blog里的构造矩阵部分换成我的构造方式 ...

  5. 第一篇(那些JAVA程序BUG中的常见单词)

    The local variable xxx may not have been initialized. 局部变量xxx可能尚未初始化 local variable 局部变量 initialized ...

  6. Android 线程池系列教程(3) 创建线程池

    Creating a Manager for Multiple Threads 上一课  下一课 1.This lesson teaches you to Define the Thread Pool ...

  7. Android 线程池系列教程(1)目录

    Sending Operations to Multiple Threads 1.Dependencies and prerequisites Android 3.0 (API Level 11) o ...

  8. lavas安装

    最近在研究pwa,百度基于此写了一套开源框架lavas,学习下: 1.环境准备: lavas 安装.git安装 Node.js:https://nodejs.org/ Git:https://git- ...

  9. windows 迁移数据库

    1) Prerequisites    ---------------- - The copy of the datafiles must be done with the database clos ...

  10. AJPFX关于File类复习

    file是一个路径,分为相对路径(eclipse)和绝对路径:1.构造方法有:File(String pathname ),File(String parent ,String child),File ...