File was renamed from app/src/main/java/com/hdl/photovoltaic/utils/FileUtils.java |
| | |
| | | package com.hdl.photovoltaic.utils; |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.BitmapFactory; |
| | | import android.util.Log; |
| | | |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | |
| | | import java.io.BufferedInputStream; |
| | | import java.io.BufferedOutputStream; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStreamWriter; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Objects; |
| | | |
| | | public class HdlFileLogic { |
| | | |
| | | public class FileUtils { |
| | | private static volatile HdlFileLogic sHdlFileLogic; |
| | | |
| | | public static synchronized HdlFileLogic getInstance() { |
| | | if (sHdlFileLogic == null) { |
| | | synchronized (HdlFileLogic.class) { |
| | | if (sHdlFileLogic == null) { |
| | | sHdlFileLogic = new HdlFileLogic(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return sHdlFileLogic; |
| | | } |
| | | |
| | | private static final String TAG = "FileUtils"; |
| | | |
| | | public static final String userId = ""; |
| | | |
| | | /** |
| | | * 获取内部存储文件路径 |
| | | * |
| | | * @param context 上下文 |
| | | * @return - |
| | | */ |
| | | public static String getInternalStoreFilesPath(Context context) { |
| | | if (context == null) { |
| | | return ""; |
| | | } |
| | | return context.getFilesDir().getAbsolutePath(); |
| | | private String getInternalStoreFilesPath() { |
| | | return HDLApp.getInstance().getFilesDir().getAbsolutePath(); |
| | | } |
| | | |
| | | public static File createFile(String dirPath, String fileName) { |
| | | /** |
| | | * 获取App存放文件的根路径 |
| | | */ |
| | | public String getAppFilesPath() { |
| | | return HDLApp.getInstance().getFilesDir().getAbsolutePath() + userId + "/home"; |
| | | } |
| | | |
| | | public File createFile(String dirPath, String fileName) { |
| | | try { |
| | | File dirFile = new File(dirPath); |
| | | if (!dirFile.exists()) { |
| | |
| | | /** |
| | | * 创建文件夹---之所以要一层层创建,是因为一次性创建多层文件夹可能会失败! |
| | | */ |
| | | public static boolean createFileDir(File dirFile) { |
| | | public boolean createFileDir(File dirFile) { |
| | | if (dirFile == null) { |
| | | return true; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public static void writeFile(String path, String data) { |
| | | public void writeFile(String path, String data) { |
| | | try { |
| | | File file = new File(path); |
| | | if (!file.exists()) { |
| | |
| | | |
| | | } |
| | | |
| | | public static String readFile(String filepath) { |
| | | public String readFile(String filepath) { |
| | | try { |
| | | String fileContent = ""; |
| | | if (null == filepath) { |
| | |
| | | /** |
| | | * 把位图数据保存到指定路径的图片文件 |
| | | */ |
| | | public static void writeImage(String path, Bitmap bitmap) { |
| | | public void writeImage(String path, Bitmap bitmap) { |
| | | try { |
| | | //根据指定文件路径构建缓存输出流对象 |
| | | BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(path)); |
| | |
| | | /** |
| | | * 从指定路径的图片文件中读取位图数据 |
| | | */ |
| | | public static Bitmap readImage(String path) { |
| | | public Bitmap readImage(String path) { |
| | | try { |
| | | //根据指定文件路径构建缓存输入流对象 |
| | | BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path)); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |