通过文件输入流读取问价

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

  1. Java输入/输出流体系

    在用java的io流读写文件时,总是被它的各种流能得很混乱,有40多个类,理清啦,过一段时间又混乱啦,决定整理一下!以防再忘 Java输入/输出流体系 1.字节流和字符流 字节流:按字节读取.字符流: ...

  2. 深入理解Java输入输出流

    Java.io包的File类,File类用于目录和文件的创建.删除.遍历等操作,但不能用于文件的读写. Java 对文件的写入和读取涉及到流的概念,写入为输出流,读取为输入流.如何理解流的概念呢?可以 ...

  3. Java 输入输出流 转载

    转载自:http://blog.csdn.net/hguisu/article/details/7418161 1.什么是IO Java中I/O操作主要是指使用Java进行输入,输出操作. Java所 ...

  4. Java输入输出流(一)——常用的输入输出流

    1.流的概念:在Java中,流是从源到目的地的字节的有序序列.Java中有两种基本的流--输入流(InputStream)和输出流(OutputStream). 根据流相对于程序的另一个端点的不同,分 ...

  5. java输入输出流总结 转载

    一.基本概念 1.1 什么是IO?     IO(Input/Output)是计算机输入/输出的接口.Java中I/O操作主要是指使用Java进行输入,输出操作.     Java所有的I/O机制都是 ...

  6. java输入输出流(内容练习)

    1,编写一个程序,读取文件test.txt的内容并在控制台输出.如果源文件不存在,则显示相应的错误信息. package src; import java.io.File; import java.i ...

  7. Java输入输出流(转载)

    转自http://blog.csdn.net/hguisu/article/details/7418161 目录(?)[+] 1.什么是IO Java中I/O操作主要是指使用Java进行输入,输出操作 ...

  8. 转 Java输入输出流详解(非常详尽)

    转  http://blog.csdn.net/zsw12013/article/details/6534619 通过数据流.序列化和文件系统提供系统输入和输出. Java把这些不同来源和目标的数据都 ...

  9. java输入输出流(I/O)总结

    io流的 四个基本类 java.io包中包含了流式I/O所需要的所有类.在java.io包中有四个基本类:InputStream.OutputStream及Reader.Writer类,它们分别处理字 ...

随机推荐

  1. 【整理】Angularjs 监听ng-repeat onfinishrender事件

    http://stackoverflow.com/questions/15207788/calling-a-function-when-ng-repeat-has-finished http://ww ...

  2. 图像特征提取:Sobel边缘检测

    前言 点和线是做图像分析时两个最重要的特征,而线条往往反映了物体的轮廓,对图像中边缘线的检测是图像分割与特征提取的基础.文章主要讨论两个实际工程中常用的边缘检测算法:Sobel边缘检测和Canny边缘 ...

  3. Tushare的安装

    TuShare是一个免费.开源的python财经数据接口包.主要实现对股票等金融数据从数据采集.清洗加工到数据存储的过程,能够为金融分析人员提供快速.整洁.和多样的便于分析的数据. 考虑到python ...

  4. HDOJ 1590

    #include<stdio.h> #include<iostream> #include<stdlib.h> #include<string.h> u ...

  5. HDOJ 1022 模拟栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. 将XML解析成DOM文档

    在支持html5的浏览其中,可以使用标准解析器DOMParser对象进行解析html或者xml等字符串 var data = '<div></div>'; var tmp = ...

  7. C 结构体小结

    看了三天结构体,是时候总结一下了. 关于结构体的声明: struct Student { ]; char sex; int age; ]; }; /*然后定义一个Student 类型的 student ...

  8. JavaScript常用事件

    一般事件 事件 浏览器支持 描述 onClick HTML: 2 | 3 | 3.2 | 4   Browser: IE3 | N2 | O3 鼠标点击事件,多用在某个对象控制的范围内的鼠标点击 on ...

  9. Android 和iOS中 View的滚动

    在最近的程序中用到了Android中的View的滚动,记录一下,待总结.

  10. poj 2013 Symmetric Order 解题报告

    题目链接:http://poj.org/problem?id=2013 设长度非递减的字串序列为s[1]...s[n].设计递归子程序print(n),其中n为字串序号,每分析1个字串,n=n-1. ...