| | |
| | | import com.anyun.exam.lib.MyLog; |
| | | import com.anyun.exam.lib.util.ByteUtil; |
| | | |
| | | import java.io.BufferedOutputStream; |
| | | import java.io.BufferedReader; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | |
| | | Log.i(TAG, "createdirs: 目录已经存在"); |
| | | } |
| | | |
| | | } |
| | | |
| | | public static boolean isMapExist(Context context,String mapName){ |
| | | File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+context.getPackageName(),mapName); |
| | | |
| | | if (file.exists()){ |
| | | return true; |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public static StringBuffer readTxtFileFromSD(Context context,String fileName,boolean isRootDir){ |
| | |
| | | } |
| | | return data; |
| | | } |
| | | public static void main(String[] args){ |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根目录下+"包名"的路径下的子路径 |
| | | * @param context |
| | | * @param subDir |
| | | */ |
| | | public static void createdirs(Context context,String subDir){ |
| | | String dir = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+context.getPackageName()+"/"; |
| | | if (!TextUtils.isEmpty(subDir)){ |
| | | dir += subDir+"/"; |
| | | } |
| | | File file = new File(dir); |
| | | if (!file.exists()){ |
| | | file.mkdirs(); |
| | | |
| | | }else{ |
| | | Log.i(TAG, "createdirs: 目录已经存在"); |
| | | } |
| | | |
| | | } |
| | | public static void writeTxtFileToSD(Context context, String fileName, String content,String subDir){ |
| | | Log.i(TAG, "writeTxtFileToSD: content:"+content); |
| | | createdirs(context,subDir); |
| | | String dir = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+context.getPackageName()+"/"+subDir+"/"; |
| | | File file = new File(dir,fileName); |
| | | if (file.exists()){ |
| | | file.delete(); |
| | | } |
| | | try { |
| | | OutputStream outputStream = new FileOutputStream(file); |
| | | BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream); |
| | | bufferedOutputStream.write(content.getBytes()); |
| | | bufferedOutputStream.flush(); |
| | | outputStream.close(); |
| | | bufferedOutputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |