| | |
| | | import android.content.res.Resources; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | |
| | | public class FileUtil { |
| | | /** |
| | |
| | | return stringBuffer; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param fromFile 源文件路径包括文件名(绝对路径) |
| | | * @param toFile |
| | | */ |
| | | public static void copyFile(String fromFile,String toFile){ |
| | | |
| | | try { |
| | | InputStream inputStream =new FileInputStream(fromFile); |
| | | OutputStream outputStream = new FileOutputStream(toFile); |
| | | byte[] bytes = new byte[1024]; |
| | | while ((inputStream.read(bytes))>0){ |
| | | outputStream.write(bytes); |
| | | } |
| | | inputStream.close(); |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 拷贝assert目录下的文件到 安装包目录下 |
| | | * @param context |
| | | * @param assertfileName |
| | | */ |
| | | public static void copyAssertFileToSD(Context context,String assertfileName){ |
| | | try { |
| | | InputStream inputStream = null; |
| | | try { |
| | | inputStream = context.getAssets() |
| | | .open(assertfileName); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | OutputStream outputStream = new FileOutputStream( new File(context.getExternalFilesDir(null), assertfileName)); |
| | | byte[] bytes = new byte[1024]; |
| | | while ((inputStream.read(bytes))>0){ |
| | | outputStream.write(bytes); |
| | | } |
| | | inputStream.close(); |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |