- import java.io.*;
- public class SS {
- public static void main(String[] args) throws Exception {
- File f = new File("d:\\大型数据库文件.mdf");
- FileInputStream fis = new FileInputStream(f);
- //如果下面的语句使用BufferedOutputStream来修饰则带来更好的性能现。
- FileOutputStream fos = new FileOutputStream("e:\\" + f.getName());
- int length = 0;
- byte[] b = new byte[1024];
- while((length = fis.read(b)) != -1)
- {
- fos.write(b, 0, length);
- }
- fos.close();
- fis.close();
- }
- }
- 在读取txt文件时,可能会遇到中文乱码情况,解决办法如下:
- Java代码
- private String getTextString(String pathandname) throws IOException{
-
- String str="";
-
- FileInputStream fis = new FileInputStream(pathandname);
- // InputStreamReader isr=new InputStreamReader(fis, "gbk");
- // BufferedReader br=new BufferedReader(isr);
-
- int size=fis.available();
-
- byte[] buffer=new byte[size];
-
- fis.read(buffer);
-
- fis.close();
-
- str = new String(buffer,"GBK");//支持双字节字符
-
- myApp.setCharNumofString(str.length());//存储总字符数
-
- return str;
- }
原文地址:http://androidstudy.iteye.com/blog/788562
阅读(878) | 评论(0) | 转发(0) |