Android读取文件

从sd卡中读取一个文件,读取和JAVA类似。

public String loadContentFromSDCard(String fileName) {
    	String content = null;
    	
    	try{
    		File f = new File("sdcard/" + fileName);
    		int len = (int)f.length();
    		byte[] buf= new byte[len];
    		
    		FileInputStream fis = new FileInputStream(f);
    		fis.read(buf);
    		fis.close();
    		content = new String(buf,"UTF-8");
    	}catch (Exception e) {
    		Toast.makeText(this, "没有找到文件", Toast.LENGTH_SHORT).show();
    	}

    	return content;
    }

  

posted on 2012-08-14 22:24  ShunHoo  阅读(80)  评论(0编辑  收藏  举报

导航