| | |
| | | import android.util.Log; |
| | | |
| | | import com.anyun.exam.lib.MyLog; |
| | | import com.anyun.exam.lib.util.ByteUtil; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"ISO-8859-1"); |
| | | InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"GB2312"); |
| | | BufferedReader bufferedReader = new BufferedReader(inputStreamReader); |
| | | while((lineTxt = bufferedReader.readLine()) != null){ |
| | | // System.out.println( ByteUtil.byte2hex(lineTxt.getBytes("ISO-8859-1"))); |
| | | |
| | | stringBuffer.append(lineTxt); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public static byte[] readLocalFile(Context context,String fileName) throws IOException { |
| | | InputStream inputStream = null; |
| | | String dir = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"; |
| | | File file = new File(dir,fileName); |
| | | if (!file.exists()){ |
| | | MyLog.d(TAG,dir+"目录下"+fileName+"文件不存在"); |
| | | return null; |
| | | } |
| | | try { |
| | | inputStream = new FileInputStream(file); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | byte[] data = toByteArray(inputStream); |
| | | inputStream.close(); |
| | | return data; |
| | | } |
| | | private static byte[] toByteArray(InputStream in) throws IOException { |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[1024 * 4]; |
| | | int n = 0; |
| | | while ((n = in.read(buffer)) != -1) { |
| | | out.write(buffer, 0, n); |
| | | } |
| | | return out.toByteArray(); |
| | | } |
| | | |
| | | } |