| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | import android.content.Context; |
| | | import android.content.res.AssetManager; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.BitmapFactory; |
| | | import android.os.Environment; |
| | | import android.text.TextUtils; |
| | | |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | |
| | | 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.util.Objects; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 打开资源文件 |
| | | * |
| | | * @param fileName 文件名 |
| | | * @param context 上下文 |
| | | * @return 返回json字符串 |
| | | */ |
| | | public String openAssetsFileJson(String fileName, Context context) { |
| | | if (TextUtils.isEmpty(fileName)) { |
| | | return ""; |
| | | } |
| | | //将json数据变成字符串 |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | try { |
| | | //获取assets资源管理器 |
| | | AssetManager assetManager = context.getAssets(); |
| | | //通过管理器打开文件并读取 |
| | | BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open(fileName))); |
| | | String line; |
| | | while ((line = bf.readLine()) != null) { |
| | | stringBuilder.append(line); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return stringBuilder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 判断路径是否合法 |
| | | * |
| | | * @param path 路径 |