checktest.java

来自「java应用开发详解」· Java 代码 · 共 50 行

JAVA
50
字号
import java.io.*;
import java.util.zip.*;

public class checkTest 
{
	public static void main(String[] args) throws IOException 
	{		
	       	Adler32 inChecker = new Adler32();
	       	Adler32 outChecker = new Adler32();
		CheckedInputStream in = null;
       		CheckedOutputStream out = null;

       		try
       		{
           		//在文件流的基础上建立CheckedStream
           		//Adler32在构造方法中作为参数被引用
           		in = new CheckedInputStream(
			   new FileInputStream("beChecked.txt"),
			   inChecker);
           		out = new CheckedOutputStream(
			    new FileOutputStream("outChecked.txt"),
			    outChecker);
       		}
       		catch (FileNotFoundException e) 
       		{
           		System.err.println("checkTest: " + e);
           		System.exit(-1);
       		}
       		catch (IOException e) 
       		{
           		System.err.println("checkTest: " + e);
           		System.exit(-1);
       		}

       		int c;

       		while ((c = in.read()) != -1)
          		out.write(c);

       		
       		System.out.println("Input stream check sum: " +
			  inChecker.getValue());
       		System.out.println("Output stream check sum: " +
			  outChecker.getValue());

       		in.close();
       		out.close();
    	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?