java 输入输出流1 FileInputStrem&&FileOutStream
通过文件输入流读取问价
package unit6; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.channels.FileLockInterruptionException; public class mytype { public static void main(String[] args) {
try{
FileInputStream fin= new FileInputStream(args[0]);
int ch=fin.read();
while(ch!=-1){
System.out.println((char )ch);
ch=fin.read();
}
}catch (ArrayIndexOutOfBoundsException e) {
System.out.println("use the right style: java mytype filename");
System.exit(0); }catch (FileNotFoundException e2) { System.out.println("file does not find");
}catch (IOException e3) { System.out.println("input stream error!");
}
}
}
通过文件输入输出流复制文件
package unit6; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import org.xml.sax.InputSource; public class copy { public static void main(String[] args) {
int numberRead=0;
InputStream in = null;
OutputStream out = null;
byte buf[] = new byte[512];
if(args.length!=2){
System.out.println("Usage: java copy sourcefile destfile");
System.exit(0);
}
try{
in=new FileInputStream(args[0]);
out= new FileOutputStream(args[1]);
while((numberRead=in.read(buf))!=-1){
out.write(buf,0,numberRead);
}
}catch (FileNotFoundException e1) { System.out.println(args[0]+" not found");
System.exit(0);
}catch (IOException e2) { System.out.println("Error reading/writing file.");
}finally{
try{
in.close();
out.close();
}catch (Exception e) { e.printStackTrace();
}
}
System.out.println("1 file copyed");
}
}
按文件读入字符,并且对文件进行加密,保存为新的文件
package unit6; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; public class jmcopy { public static void main(String[] args) {
int ch;
FileInputStream fin = null;
FileOutputStream fout =null;
try{
fin=new FileInputStream(args[0]);
fout=new FileOutputStream(args[1]);
int key=args[2].length();
ch=fin.read();
while(ch!=-1){
fout.write(ch^key);
ch=fin.read();
}
fin.close();fout.close();
}catch (ArrayIndexOutOfBoundsException e1) { System.out.println("fomat error,type: java jmcopy sourcefile destfile key");
System.exit(0);
}catch (FileNotFoundException e2) { System.out.println("file not found");
}catch (IOException e3) { System.out.println("strem error!");
}
}
}
java 输入输出流1 FileInputStrem&&FileOutStream的更多相关文章
- Java输入/输出流体系
在用java的io流读写文件时,总是被它的各种流能得很混乱,有40多个类,理清啦,过一段时间又混乱啦,决定整理一下!以防再忘 Java输入/输出流体系 1.字节流和字符流 字节流:按字节读取.字符流: ...
- 深入理解Java输入输出流
Java.io包的File类,File类用于目录和文件的创建.删除.遍历等操作,但不能用于文件的读写. Java 对文件的写入和读取涉及到流的概念,写入为输出流,读取为输入流.如何理解流的概念呢?可以 ...
- Java 输入输出流 转载
转载自:http://blog.csdn.net/hguisu/article/details/7418161 1.什么是IO Java中I/O操作主要是指使用Java进行输入,输出操作. Java所 ...
- Java输入输出流(一)——常用的输入输出流
1.流的概念:在Java中,流是从源到目的地的字节的有序序列.Java中有两种基本的流--输入流(InputStream)和输出流(OutputStream). 根据流相对于程序的另一个端点的不同,分 ...
- java输入输出流总结 转载
一.基本概念 1.1 什么是IO? IO(Input/Output)是计算机输入/输出的接口.Java中I/O操作主要是指使用Java进行输入,输出操作. Java所有的I/O机制都是 ...
- java输入输出流(内容练习)
1,编写一个程序,读取文件test.txt的内容并在控制台输出.如果源文件不存在,则显示相应的错误信息. package src; import java.io.File; import java.i ...
- Java输入输出流(转载)
转自http://blog.csdn.net/hguisu/article/details/7418161 目录(?)[+] 1.什么是IO Java中I/O操作主要是指使用Java进行输入,输出操作 ...
- 转 Java输入输出流详解(非常详尽)
转 http://blog.csdn.net/zsw12013/article/details/6534619 通过数据流.序列化和文件系统提供系统输入和输出. Java把这些不同来源和目标的数据都 ...
- java输入输出流(I/O)总结
io流的 四个基本类 java.io包中包含了流式I/O所需要的所有类.在java.io包中有四个基本类:InputStream.OutputStream及Reader.Writer类,它们分别处理字 ...
随机推荐
- lamp环境centos6.4
http://www.centos.bz/2011/09/centos-compile-lamp-apache-mysql-php/comment-page-1/#comments 编译安装: 首先卸 ...
- 微信和WeChat的合并月活跃账户达6.97亿
腾讯最新财报显示,微信和WeChat的合并月活跃账户于2015年底达6.97亿,同比增长39%.2016年初春节假期期间,通过微信支付收发的红包数量仅在6天内就超过320亿,同比增长9倍. 腾讯网络广 ...
- bc.34.B.Building Blocks(贪心)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 实战 -- Redis2.4.2集成spring3.2.2
redis.host=... redis.port= redis.pass= redis.timeout= #最大能够保持idel状态的对象数 redis.maxIdle= #最大分配的对象数 red ...
- web_url、web_custom_request、web_submit_data、web_submit_form的使用实例
业务:根据url获取图片用web_url()函数访问数据;请求方式:HTTP GET 请求;Action(){web_url("imageproxytest", "URL ...
- [Effective JavaScript 笔记] 第6条:了解分号插入的局限
分号可以省略 js可以在语句结束不强制加分号.(建议还是添加,不添加分号往往会出现不易发现的BUG) function Point(x,y){ this.x=x||0; this.y=y||0; } ...
- Linux下使用Speedtest测试网速
导读 Speedtest是用来测试网络性能的开源软件,在Linux下面安装Speedtest可以用来测试网络出口的上传和下载速度,帮助排查网络方面导致的故障. Speedtest介绍 由于公司几个项目 ...
- CUDA 6.5 && VS2013 && Win7:创建CUDA项目
运行环境: Win7+VS2013+CUDA6.5 1.创建win32空项目 2.右键项目解决方案-->生成项目依赖项-->生成自定义 3.右键项目解决方案-->属性-->配置 ...
- HDU1068 最大独立点集
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- neutron 中 flat vlan gre vxlan的区别
In a flat network, everyone shares the same network segment. For example, say 2 tenants are sharing ...