java 生成oracle block(dba 手记2 77页c++程序改)
/**
* @(#)dbblockreadWrite.java
*
* @author lihongjie
* @version 1.00 2011/11/6
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.*;
public class dbblockreadWrite {
/**
* Creates a new instance of dbblockreadWrite.
*/
public dbblockreadWrite() {
}
/**
* @param args the command line arguments
*/
public static void readWritFileByBytes(String fileName,int Blksiz) {
File file = new File(fileName);
File outFile = new File(fileName+"out");//定义拷贝目标文件
InputStream in = null;
FileOutputStream out=null;
BufferedOutputStream bout=null;
try {
// 一次读多个字节
byte[] tempbytes = new byte[Blksiz];
byte[] errdbytes = new byte[Blksiz];
byte[] a = HexString2Bytes("ff");
byte[] b = HexString2Bytes("04");
byte[] c = HexString2Bytes("f0");
byte[] d = HexString2Bytes("f0");
errdbytes[14]=a[0];
errdbytes[15]=b[0];
errdbytes[16]=c[0];
errdbytes[17]=d[0];
System.out.println(Bytes2HexString(errdbytes).substring(1,60)); //test。。。
//errdbytes[0]=HexString2Bytes("0f");
int byteread = 0;
in = new FileInputStream(fileName);
int avaibytes=in.available()/8102;
out = new FileOutputStream(outFile);
bout = new BufferedOutputStream(out);
while (((byteread = in.read(tempbytes)) != -1)&& (avaibytes>-1)) {
//System.out.write(tempbytes, 0, byteread);
bout.write(tempbytes, 0, byteread);
if (byteread == -1){
bout.write(errdbytes, 0,Blksiz );//后面参数 该是什么呢,嘎嘎 字节数
}
avaibytes--;
}
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
bout.close();
} catch (IOException e1) {
}
}
}
}
public static byte uniteBytes(byte src0, byte src1) {
byte _b0 = Byte.decode("0x" + new String(new byte[]{src0})).byteValue();
_b0 = (byte)(_b0 << 4);
byte _b1 = Byte.decode("0x" + new String(new byte[]{src1})).byteValue();
byte ret = (byte)(_b0 ^ _b1);
return ret;
}
/**
* 将指定字符串src,以每两个字符分割转换为16进制形式
* 如:"2B44EFD9" –> byte[]{0x2B, 0×44, 0xEF, 0xD9}
* @param src String
* @return byte[]
*/
public static byte[] HexString2Bytes(String src){
byte[] ret = new byte[src.length()/2];
byte[] tmp = src.getBytes();
for(int i=0; i< tmp.length/2; i++){
ret[i] = uniteBytes(tmp[i*2], tmp[i*2+1]);
}
return ret;
}
/**
*
* @param b byte[]
* @return String
*/
public static String Bytes2HexString(byte[] b) {
String ret = "";
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
ret += hex.toUpperCase();
}
return ret;
}
public static void main(String[] args) {
readWritFileByBytes( "rac网上所有问题.docx",8192);
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9879835/viewspace-1056190/ ,如需转载,请注明出处,否则将追究法律责任。