-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileController.java
More file actions
139 lines (121 loc) · 3.62 KB
/
FileController.java
File metadata and controls
139 lines (121 loc) · 3.62 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.unity.androidplugin;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;
import android.content.Context;
import com.unity3d.player.UnityPlayerActivity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
public class FileController {
public static Context ShowContext = null;
public static void SetContext(Context con)
{
ShowContext = con;
}
public static void ShowToast(String info,Context context)
{
Toast.makeText(context,info,Toast.LENGTH_LONG).show();
}
public static void ShowToast(String info)
{
Toast.makeText(ShowContext,info,Toast.LENGTH_LONG).show();
}
public static byte[] ReadFileData(String Path)
{
File file = new File(Path);
byte[] data = null;
if(file.exists()) {
try {
FileInputStream fs = new FileInputStream(file.getAbsolutePath());
data = new byte[(int)file.length()];
fs.read(data,0,data.length);
fs.close();
return data;
}
catch (Exception e) {
e.printStackTrace();
}
}
return data;
}
public static boolean CreateFile(String Path)
{
File file = new File(Path);
if(file.exists())
{
ShowToast("文件已存在:"+file.getAbsolutePath());
return false;
}else
{
try
{
file.createNewFile();
ShowToast("文件创建成功:" + file.getAbsolutePath());
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
}
public static void CreateFileTest(String FileName)
{
File file = new File(Environment.getDataDirectory(),FileName);
if(file.exists())
{
ShowToast("文件已存在:"+file.getAbsolutePath());
}else
{
try
{
file.createNewFile();
ShowToast("文件创建成功:" + file.getAbsolutePath());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public static boolean LoadFileTest(String Path)
{
File file = new File(Path);
if(file.exists())
{
byte[] data = ReadFileData(file.getAbsolutePath());
ShowToast(String.format("FileSize%1s:%2s %3s %4s %5s.",file.length(),data[0],data[1],data[2],data[3]));
return true;
}else
{
ShowToast("文件不存在:"+file.getAbsolutePath());
return false;
}
}
public static int GetFileSize(String Path)
{
File file = new File(Path);
if(file.exists())
{
ShowToast("文件大小:"+file.length());
return (int)file.length();
}else
{
ShowToast("文件不存在:"+file.getAbsolutePath());
return -1;
}
}
public static String GetPath()
{
ShowToast(Environment.getExternalStorageDirectory().getAbsolutePath());
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
public static String[] GetALLFiles(String Path,String Fliter)
{
File file = new File(Path);
return file.list();
}
}