| | |
| | | package cn.com.basic.face.util;
|
| | |
|
| | | import android.graphics.Bitmap;
|
| | | import android.graphics.BitmapFactory;
|
| | |
|
| | | import java.io.BufferedOutputStream;
|
| | | 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.RandomAccessFile;
|
| | |
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | |
| | | return new File(dir, shortFileName);
|
| | | }
|
| | |
|
| | | public static File getPhotoFile() {
|
| | | File dir = new File(MainActivity.getInstance().getFilesDir().getAbsolutePath());
|
| | | File[] photoFiles = dir.listFiles();
|
| | | if (photoFiles != null) {
|
| | | for (File file : photoFiles) {
|
| | | if (file.isDirectory()) {
|
| | | continue;
|
| | | }
|
| | | String name = file.getName();
|
| | | if (name.length() != "c248fe8f-6da5-4ec9-bffa-1a11bcf2fdc7".length()) {
|
| | | continue;
|
| | | }
|
| | | if (file.isFile()) {
|
| | | return file;
|
| | | }
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | | public static byte[] readFile(File file) {
|
| | | // Open file
|
| | |
| | | e.printStackTrace();
|
| | | } finally {
|
| | | try {
|
| | | f.close();
|
| | | if (f != null) {
|
| | | f.close();
|
| | | }
|
| | | }catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | public static String convertStreamToString(InputStream is) throws Exception {
|
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
| | | StringBuilder sb = new StringBuilder();
|
| | | String line = null;
|
| | | while ((line = reader.readLine()) != null) {
|
| | | sb.append(line);
|
| | | }
|
| | | reader.close();
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | public static String getStringFromFile (String filePath) {
|
| | | try {
|
| | | File fl = new File(filePath);
|
| | | FileInputStream fin = new FileInputStream(fl);
|
| | | String ret = convertStreamToString(fin);
|
| | | fin.close();
|
| | | return ret;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return "";
|
| | | }
|
| | |
|
| | | public static Bitmap loadBitmap(String fileName) {
|
| | | String dir = MainActivity.getInstance().getFilesDir().getAbsolutePath();
|
| | | File file = new File(dir, fileName);
|
| | | if (file.exists()) {
|
| | | BitmapFactory.Options options = new BitmapFactory.Options();
|
| | | options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
| | | Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
| | | return bitmap;
|
| | | } else {
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | }
|