import java.io.* ;
class Send implements Runnable{ // 线程类
private PipedOutputStream pos = null ; // 管道输出流
public Send(){
this.pos = new PipedOutputStream() ; // 实例化输出流
}
public void run(){
String str = "Hello World!!!" ; // 要输出的内容
try{
this.pos.write(str.getBytes()) ;
}catch(IOException e){
e.printStackTrace() ;
}
try{
this.pos.close() ;
}catch(IOException e){
e.printStackTrace() ;
}
}
public PipedOutputStream getPos(){ // 得到此线程的管道输出流
return this.pos ;
}
};
class Receive implements Runnable{
private PipedInputStream pis = null ; // 管道输入流
public Receive(){
this.pis = new PipedInputStream() ; // 实例化输入流
}
public void run(){
byte b[] = new byte[1024] ; // 接收内容
int len = 0 ;
try{
len = this.pis.read(b) ; // 读取内容
}catch(IOException e){
e.printStackTrace() ;
}
try{
this.pis.close() ; // 关闭
}catch(IOException e){
e.printStackTrace() ;
}
System.out.println("接收的内容为:" + new String(b,0,len)) ;
}
public PipedInputStream getPis(){
return this.pis ;
}
};
public class PipedDemo{
public static void main(String args[]){
Send s = new Send() ;
Receive r = new Receive() ;
try{
s.getPos().connect(r.getPis()) ; // 连接管道
}catch(IOException e){
e.printStackTrace() ;
}
new Thread(s).start() ; // 启动线程
new Thread(r).start() ; // 启动线程
}
};
import java.io.* ;
public class PrintDemo01{
public static void main(String arg[]) throws Exception{
PrintStream ps = null ; // 声明打印流对象
// 如果现在是使用FileOuputStream实例化,意味着所有的输出是向文件之中
ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "test.txt"))) ;
ps.print("hello ") ;
ps.println("world!!!") ;
ps.print("1 + 1 = " + 2) ;
ps.close() ;
}
};
import java.io.* ;
public class PrintDemo02{
public static void main(String arg[]) throws Exception{
PrintStream ps = null ; // 声明打印流对象
// 如果现在是使用FileOuputStream实例化,意味着所有的输出是向文件之中
ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "test.txt"))) ;
String name = "李兴华" ; // 定义字符串
int age = 30 ; // 定义整数
float score = 990.356f ; // 定义小数
char sex = 'M' ; // 定义字符
ps.printf("姓名:%s;年龄:%d;成绩:%f;性别:%c",name,age,score,sex) ;
ps.close() ;
}
};
import java.io.* ;
public class PrintDemo03{
public static void main(String arg[]) throws Exception{
PrintStream ps = null ; // 声明打印流对象
// 如果现在是使用FileOuputStream实例化,意味着所有的输出是向文件之中
ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "test.txt"))) ;
String name = "李兴华" ; // 定义字符串
int age = 30 ; // 定义整数
float score = 990.356f ; // 定义小数
char sex = 'M' ; // 定义字符
ps.printf("姓名:%s;年龄:%s;成绩:%s;性别:%s",name,age,score,sex) ;
ps.close() ;
}
};

最新文章

  1. 初识GO语言——安装Go语言
  2. Selenium2+python自动化15-select下拉框
  3. SoPC/Qsys杂谈
  4. CSS样式display:none和visibility:hidden的区别
  5. 【算法】数组与矩阵问题——找到无序数组中最小的k个数
  6. (莱昂氏unix源代码分析导读-49) 字符缓冲区
  7. python自动发邮件
  8. vue和mpvue
  9. dnmp(docker的lnmp)安装WordPress之后图片上传问题 问题:图片上传大小问题解决和 报错413 Request Entity Too Large
  10. Windows 版 SourceTree 免登录跳过初始设置的方法
  11. ZY
  12. react-redux中的数据传递
  13. 北大poj-1021
  14. IDEA中通过工具类实现对数据库的增删改查
  15. Python脱产8期 Day10 2019/4/24
  16. java web----MINA框架使用
  17. mysql5.7一键安装脚本
  18. How to export a model from SolidWorks to Google SketchUp
  19. Oracle使用技巧及PL/SQL Developer配置
  20. jsp动作之 setProperty

热门文章

  1. 杭电 2096 小明A+B
  2. Codeforces Round #608 (Div. 2) - D. Portals(贪心)
  3. Pako.js压缩解压,vue压缩解压,前后端之间高效数据传输
  4. 弱密码检测JR!
  5. python集合操作方法详解
  6. Centos610无桌面安装Docker-内核升级
  7. 笔记-爬虫部署及运行工具-scrapydweb
  8. string和 new string的区别
  9. 汇编语言从入门到精通-5微机CPU的指令系统1
  10. jquery $.ajax status为200 却调用了error方法