吴裕雄--天生自然JAVAIO操作学习笔记:System类对IO的支持和BuffereRead
import java.io.OutputStream ;
import java.io.IOException ;
public class SystemDemo01{
public static void main(String args[]){
OutputStream out = System.out ; // 此时的输出流是向屏幕上输出
try{
out.write("hello world!!!".getBytes()) ; // 向屏幕上输出
}catch(IOException e){
e.printStackTrace() ; // 打印异常
}
try{
out.close() ; // 关闭输出流
}catch(IOException e){
e.printStackTrace() ;
}
}
};
public class SystemDemo02{
public static void main(String args[]){
String str = "hello" ; // 声明一个非数字的字符串
try{
System.out.println(Integer.parseInt(str)) ; // 转型
}catch(Exception e){
System.err.println(e) ;
}
}
};
public class SystemDemo03{
public static void main(String args[]){
String str = "hello" ; // 声明一个非数字的字符串
try{
System.out.println(Integer.parseInt(str)) ; // 转型
}catch(Exception e){
System.out.println(e) ;
}
}
};
import java.io.InputStream ;
public class SystemDemo04{
public static void main(String args[]) throws Exception { // 所有异常抛出
InputStream input = System.in ; // 从键盘接收数据
byte b[] = new byte[5] ; // 开辟空间,接收数据
System.out.print("请输入内容:") ; // 提示信息
int len = input.read(b) ; // 接收数据
System.out.println("输入的内容为:" + new String(b,0,len)) ;
input.close() ; // 关闭输入流
}
};
import java.io.InputStream ;
public class SystemDemo05{
public static void main(String args[]) throws Exception { // 所有异常抛出
InputStream input = System.in ; // 从键盘接收数据
StringBuffer buf = new StringBuffer() ; // 使用StringBuffer接收数据
System.out.print("请输入内容:") ; // 提示信息
int temp = 0 ; // 接收内容
while((temp=input.read())!=-1){
char c = (char) temp ; // 将数据变为字符
if(c=='\n'){ // 退出循环,输入回车表示输入完成
break ;
}
buf.append(c) ; // 保存内容
}
System.out.println("输入的内容为:" + buf) ;
input.close() ; // 关闭输入流
}
};
import java.io.File ;
import java.io.FileOutputStream ;
import java.io.PrintStream ;
public class SystemDemo06{
public static void main(String args[]) throws Exception {
System.setOut(
new PrintStream(
new FileOutputStream("d:" +
File.separator + "red.txt"))) ; // System.out输出重定向
System.out.print("www.mldnjava.cn") ; // 输出时,不再向屏幕上输出
System.out.println(",李兴华") ;
}
};
import java.io.File ;
import java.io.FileOutputStream ;
import java.io.PrintStream ;
public class SystemDemo07{
public static void main(String args[]){
String str = "hello" ; // 声明一个非数字的字符串
try{
System.out.println(Integer.parseInt(str)) ; // 转型
}catch(Exception e){
try{
System.setOut(
new PrintStream(
new FileOutputStream("d:"
+ File.separator + "err.log"))) ; // 输出重定向
}catch(Exception e1){ }
System.out.println(e) ;
}
}
};
import java.io.ByteArrayOutputStream ;
import java.io.PrintStream ;
public class SystemDemo08{
public static void main(String args[]) throws Exception{ // 所有异常抛出
ByteArrayOutputStream bos = null ; // 声明内存输出流
bos = new ByteArrayOutputStream() ; // 实例化
System.setErr(new PrintStream(bos)) ; // 输出重定向
System.err.print("www.mldnjava.cn") ; // 错误输出,不再向屏幕上输出
System.err.println("李兴华") ; // 向内存中输出
System.out.println(bos) ; // 输出内存中的数据
}
};
import java.io.FileInputStream ;
import java.io.InputStream ;
import java.io.File ;
public class SystemDemo09{
public static void main(String args[]) throws Exception{ // 所有异常抛出
System.setIn(new FileInputStream("d:"
+ File.separator + "demo.txt")) ; // 设置输入重定向
InputStream input = System.in ; // 从文件中接收数据
byte b[] = new byte[1024] ;// 开辟空间,接收数据
int len = input.read(b) ; //接收
System.out.println("输入的内容为:" + new String(b,0,len)) ;
input.close() ; // 关闭输入流
}
};
import java.io.* ;
public class BufferedReaderDemo01{
public static void main(String args[]){
BufferedReader buf = null ; // 声明对象
buf = new BufferedReader(new InputStreamReader(System.in)) ; // 将字节流变为字符流
String str = null ; // 接收输入内容
System.out.print("请输入内容:") ;
try{
str = buf.readLine() ; // 读取一行数据
}catch(IOException e){
e.printStackTrace() ; // 输出信息
}
System.out.println("输入的内容为:" + str) ;
}
};
吴裕雄--天生自然JAVAIO操作学习笔记:System类对IO的支持和BuffereRead的更多相关文章
- 吴裕雄--天生自然JAVAIO操作学习笔记:单人信息管理程序
import java.io.* ; public class ExecDemo03{ public static void main(String args[]) throws Exception{ ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:字符编码与对象序列化
public class CharSetDemo01{ public static void main(String args[]){ System.out.println("系统默认编码: ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:压缩流与回退流
import java.io.File ; import java.io.FileInputStream ; import java.io.InputStream ; import java.util ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:IO操作实例、Scanner、数据操作流与合并流
import java.io.* ; public class ExecDemo01{ public static void main(String args[]) throws Exception{ ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:字节流与字符流操作
import java.io.* ; public class Copy{ public static void main(String args[]){ if(args.length!=2){ // ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:RandomAccessFile
import java.io.File ; import java.io.RandomAccessFile ; public class RandomAccessFileDemo01{ // 所有的异 ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:File类
import java.io.File ; import java.io.IOException ; public class FileDemo01{ public static void main( ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:投票程序
public class ExecDemo{ public static void main(String args[]){ new Operate() ; } }; import java.io.B ...
- 吴裕雄--天生自然JAVAIO操作学习笔记:内存操作流、管道流与打印流操作
import java.io.* ; class Send implements Runnable{ // 线程类 private PipedOutputStream pos = null ; // ...
随机推荐
- Python与线性代数——Numpy中的matrix()和array()的区别
Numpy中matrix必须是2维的,但是 numpy中array可以是多维的(1D,2D,3D····ND).matrix是array的一个小的分支,包含于array.所以matrix 拥有arra ...
- java 使用poi 导入Excel 数据到数据库
由于我个人电脑装的Excel是2016版本的,所以这地方我使用了XSSF 方式导入 . 1先手要制定一个Excel 模板 把模板放入javaWeb工程的某一个目录下如图: 2模板建好了后,先实现模板下 ...
- Math 用法
console.log(Math.abs(-5)) 取绝对值 console.log(Math.round(5.1)) 取四舍五入 5.5 为中间值 取5 console.log(Math.ceil( ...
- 【网摘】监控 div 的内容变化
数据是动态加载而来,而当无数据时,提示一下暂无数据.而数据是可以动态在当前页面即时添加的,故在无数据时所做提示,需要隐藏,所以找了这个方法.成功在动态添加数据后,暂无数据的提示没有了. if($(&q ...
- 陶陶摘苹果(0)<P2005_1>
陶陶摘苹果 (apple.pas/c/cpp) [问题描述] 陶陶家的院子里有一棵苹果树,每到秋天树上就会结出10个苹果.苹果成熟的时候,陶陶就会跑去摘苹果.陶陶有个30厘米高的板凳,当她不能直接用 ...
- Redis数据库与python的交互
1.安装redis模块:pip install redis 2.安装好以后主要使用redis模块中的StrictRedis对象,用于连接redis服务器 3.代码如下: from redis impo ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:用户管理与权限分配
create user mr identified by mrsoft default tablespace users temporary tablespace temp; create user ...
- exp之shellcode的理解
原题请见 https://www.jarvisoj.com/challenges from pwn import * io = remote("pwn2.jarvisoj.com" ...
- py related issues
在python中安装包出现Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) pip inst ...
- 【 JdbcUtils 】mysql数据库查询
JdbcUtils package k.util; import java.sql.*; import java.util.ArrayList; import java.util.HashMap; i ...