| | |
| | | * @param filePath 全路径 |
| | | * @return 数据 |
| | | */ |
| | | public byte[] readFileByte1(String filePath) { |
| | | try { |
| | | if (!isBoolean(filePath)) { |
| | | return null; |
| | | } |
| | | File f = new File(filePath); |
| | | if (!f.exists()) { |
| | | return null; |
| | | } |
| | | FileInputStream fis = new FileInputStream(f); |
| | | byte[] bytes = FileUtils.readFileToByteArray(f);//这个方法不兼用android 6.0 |
| | | fis.close(); |
| | | System.out.println("读取文件成功--->" + filePath); |
| | | return bytes; |
| | | } catch (Exception e1) { |
| | | System.out.println("读取文件有异常--->" + e1.getMessage()); |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 读取文件 |
| | | * |
| | | * @param filePath 全路径 |
| | | * @return 数据 |
| | | */ |
| | | public byte[] readFileByte(String filePath) { |
| | | try { |
| | | if (!isBoolean(filePath)) { |
| | |
| | | return null; |
| | | } |
| | | FileInputStream fis = new FileInputStream(f); |
| | | byte[] bytes = FileUtils.readFileToByteArray(f); |
| | | BufferedInputStream bis = new BufferedInputStream(fis); |
| | | int fileLength = (int) f.length(); |
| | | byte[] bytes = new byte[fileLength]; |
| | | int len = bis.read(bytes); |
| | | bis.close(); |
| | | fis.close(); |
| | | System.out.println("读取文件成功--->" + filePath); |
| | | return bytes; |