Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1015564
  • 博文数量: 146
  • 博客积分: 3444
  • 博客等级: 中校
  • 技术积分: 1602
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-21 15:18
文章分类

全部博文(146)

文章存档

2014年(9)

2013年(3)

2012年(6)

2011年(44)

2010年(38)

2009年(46)

分类: 嵌入式

2011-12-15 09:34:50

  1. import java.io.*;
  2. public class SS {
  3.     public static void main(String[] args) throws Exception {
  4.         File f = new File("d:\\大型数据库文件.mdf");    
  5.         FileInputStream fis = new FileInputStream(f);
  6.         //如果下面的语句使用BufferedOutputStream来修饰则带来更好的性能现。

  7.         FileOutputStream fos = new FileOutputStream("e:\\" + f.getName());    
  8.         int length = 0;
  9.         byte[] b = new byte[1024];
  10.         while((length = fis.read(b)) != -1)
  11.         {
  12.             fos.write(b, 0, length);
  13.         }
  14.         fos.close();
  15.         fis.close();
  16.     }
  17. }
 
  1. 在读取txt文件时,可能会遇到中文乱码情况,解决办法如下:



  2. Java代码
  3. private String getTextString(String pathandname) throws IOException{
  4.            
  5.         String str="";
  6.            
  7.         FileInputStream fis = new FileInputStream(pathandname);
  8. // InputStreamReader isr=new InputStreamReader(fis, "gbk");

  9. // BufferedReader br=new BufferedReader(isr);

  10.            
  11.         int size=fis.available();
  12.            
  13.         byte[] buffer=new byte[size];
  14.            
  15.         fis.read(buffer);
  16.   
  17.         fis.close();
  18.               
  19.         str = new String(buffer,"GBK");//支持双字节字符

  20.            
  21.         myApp.setCharNumofString(str.length());//存储总字符数

  22.            
  23.         return str;
  24.     }
原文地址:http://androidstudy.iteye.com/blog/788562
阅读(831) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~