package com.sabirjan.CaoZuoTXT;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import org.apache.http.util.EncodingUtils;

import android.app.Activity;

public class ReadTXT {

	
	public String ReadList(Activity context)
	{
		String mReadResult="";
		try {  
		      InputStream mInputStream = context.getAssets().open("28.txt");  
		     BufferedReader mReader = new BufferedReader(new InputStreamReader(  
		                                                          mInputStream, "UTF-8"));  
		  
		      mReadResult = mReader.readLine();
		   } catch (IOException e) {  
		   // TODO Auto-generated catch block  
		   e.printStackTrace();  
		  }
		   System.out.println("Text is:"+mReadResult);

		return mReadResult;  
		
	}
	
	public String readTxt(Activity context)
	{
		String fileName = "kanun/title.txt"; //文件名字

		String res="";  

		try{  

		  InputStream in = context.getResources().getAssets().open(fileName);

		  // \Test\assets\yan.txt这里有这样的文件存在

		  int length = in.available();   

		byte [] buffer = new byte[length];   

		in.read(buffer);   

		res = EncodingUtils.getString(buffer, "UTF-8");   

		}catch(Exception e){  

		  e.printStackTrace();   

		  }
		   System.out.println("Text is:"+res);
		return res;

	}
	public String readTxt(Activity context,String strFileName)
	{
		String fileName =strFileName;//文件名字

		String res="";  

		try{  

		  InputStream in = context.getResources().getAssets().open(fileName);

		  // \Test\assets\yan.txt这里有这样的文件存在

		  int length = in.available();   

		byte [] buffer = new byte[length];   

		in.read(buffer);   

		res = EncodingUtils.getString(buffer, "UTF-8");   

		}catch(Exception e){  

		  e.printStackTrace();   

		  }
		   System.out.println("Text is:"+res);
		return res;

	}
}
