Blame view

src/com/ectrip/cyt/utils/ClearDataManager.java 1.81 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  package com.ectrip.cyt.utils;
  
  import java.io.File;
  
  import android.content.Context;
  import android.os.Environment;
  
  public class ClearDataManager {
  
  	public static void clear(Context context){
  		
  		String storageState = Environment.getExternalStorageState();
  		String savePath="";
  		try {
  			if (storageState.equals(Environment.MEDIA_MOUNTED)) {
  				deleteFilesByDirectory(context.getCacheDir());   
  
  				deleteFilesByDirectory(context.getFilesDir());
  				savePath = Environment.getExternalStorageDirectory()
  						.getAbsolutePath() + "/TripsTicketsPwd/Update/";
  				File file = new File(savePath);
  				deleteFilesByDirectory(file);   
  				if (!file.exists()) {
  					file.mkdirs();
  				}
  			}
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  		
  		if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) {        
  			deleteFilesByDirectory(context.getExternalCacheDir());   
  		}
  	}
  	
  	
  	 public static void deleteFilesByDirectory(File file) { 
  	        if (file.exists() == false) { 
  	           
  	            return; 
  	        } else { 
  	            if (file.isFile()) { 
  	                file.delete(); 
  	                return; 
  	            } 
  	            if (file.isDirectory()) { 
  	                File[] childFile = file.listFiles(); 
  	                if (childFile == null || childFile.length == 0) { 
  	                    file.delete(); 
  	                    return; 
  	                } 
  	                for (File f : childFile) { 
  	                	deleteFilesByDirectory(f); 
  	                } 
  	                file.delete(); 
  	        } }}
  
  //	private static void deleteFilesByDirectory(File directory) {
  //
  //		if (directory != null && directory.exists() && directory.isDirectory()) {       
  //			for (File item : directory.listFiles()) {             
  //				item.delete();             
  //			}
  //
  //		}
  //	}
  }