package io;
import java.io.*;
public class IOTest {
public static void main(String[] args) {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream("E:/idea/LOG1b.LOG"));
out = new BufferedOutputStream(new FileOutputStream("E:/idea/LOG2b.LOG"));
int len = 0;
//byte[] byt=new byte[1024]; //1024可变
long t1 = System.currentTimeMillis();
/* while ((len = in.read(byt)) != -1) { //-1表示读到文件末尾返回-1
out.write(len);
}*/
while ((len = in.read()) != -1) { //-1表示读到文件末尾返回-1
out.write(len);
}
long t2 = System.currentTimeMillis();
System.out.println(t2 - t1);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null)
in.close();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
try {
if (out != null)
out.close();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
} }
}
}
import java.io.*;
public class IOTest {
public static void main(String[] args) {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream("E:/idea/LOG1b.LOG"));
out = new BufferedOutputStream(new FileOutputStream("E:/idea/LOG2b.LOG"));
int len = 0;
//byte[] byt=new byte[1024]; //1024可变
long t1 = System.currentTimeMillis();
/* while ((len = in.read(byt)) != -1) { //-1表示读到文件末尾返回-1
out.write(len);
}*/
while ((len = in.read()) != -1) { //-1表示读到文件末尾返回-1
out.write(len);
}
long t2 = System.currentTimeMillis();
System.out.println(t2 - t1);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null)
in.close();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
try {
if (out != null)
out.close();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
} }
}
}
解决方案 »
- 如何将自己写的代码文件装入UIManager
- J2SE开发怎样使用数据库?新手问题
- 今天公司的一道面试题目
- 请多指教get connection from datasource fail : Cannot create JDBC driver of class '' for connect URL 'null'
- 请问如何在JLabel中加入一幅图片?
- 你们工作中会用GUI吗?
- 大虾们问一个很白的问题
- 请问能否用java写出一个隐藏的窗口?
- 关于文件读写的问题~~急~~
- 高人指点:如何取得正在编辑的表格的CellEditor的行列号?
- 什么叫java-application
- 请教一下paint和paintComponent的区别,在JFrame调用paintConponent没用吗?
oracle.jdbc.OracleDriver drive = new oracle.jdbc.OracleDriver();
DriverManager.registerDriver(drive);
Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@liuwei", "scott", "tiger");
PreparedStatement pstm1 = conn.prepareStatement("insert into wei(id,image) values(?,?)");
File file1 = new File("d:/idea/111.rar");
pstm1.setInt(1, 1);
pstm1.setBinaryStream(2, new FileInputStream(file1), (int) file1.length());
int ret1 = pstm1.executeUpdate();
System.out.println(ret1); PreparedStatement pstm2 = conn.prepareStatement("select image from wei where id = 1");
ResultSet res2 = pstm2.executeQuery(); res2.next(); InputStream in = res2.getBinaryStream(1);
FileOutputStream out = new FileOutputStream("d:/idea/222.rar"); int len = 0;
byte [] buf = new byte[1024]; while ((len = in.read(buf)) != -1) {
out.write(buf,0,len);
}
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
现在我只能告诉你怎样得到int值:
int i = Integer.parseInt(b, 2);