|
@ -1,9 +1,6 @@
|
1
|
1
|
package com.wade.mobile.func;
|
2
|
2
|
|
3
|
3
|
import java.io.File;
|
4
|
|
import java.io.FileInputStream;
|
5
|
|
import java.io.FileOutputStream;
|
6
|
|
import java.io.OutputStream;
|
7
|
4
|
|
8
|
5
|
import org.json.JSONArray;
|
9
|
6
|
import org.json.JSONException;
|
|
@ -47,9 +44,6 @@ public class MobileFile extends Plugin{
|
47
|
44
|
}
|
48
|
45
|
}
|
49
|
46
|
|
50
|
|
/**
|
51
|
|
* 获取files和sdcard/files下面所有的文件
|
52
|
|
*/
|
53
|
47
|
public void getAllFile(JSONArray param) throws Exception{
|
54
|
48
|
String fileName = param.getString(0); //相对路径参数
|
55
|
49
|
String type = param.getString(1);
|
|
@ -99,7 +93,8 @@ public class MobileFile extends Plugin{
|
99
|
93
|
String isEscape = param.getString(3);
|
100
|
94
|
String relativePath = DirectionUtil.getInstance(context).getRelativePath(fileName, type);
|
101
|
95
|
try {
|
102
|
|
String value = readFile(relativePath, isSdcard);
|
|
96
|
String absolutePath = util.getDirection(relativePath, isSdcard);
|
|
97
|
String value = FileUtil.readFile(absolutePath);
|
103
|
98
|
if ("true".equals(isEscape)) {
|
104
|
99
|
value = EscapeUnescape.escape(value);
|
105
|
100
|
}
|
|
@ -108,21 +103,6 @@ public class MobileFile extends Plugin{
|
108
|
103
|
throw new MobileException(e);
|
109
|
104
|
}
|
110
|
105
|
}
|
111
|
|
|
112
|
|
public String readFile(String relativePath, boolean isSdcard) throws Exception {
|
113
|
|
//对比
|
114
|
|
if (!isSdcard) {
|
115
|
|
File inputFile = new File(context.getFilesDir(),relativePath);
|
116
|
|
if(!inputFile.getParentFile().exists()){
|
117
|
|
inputFile.getParentFile().mkdir();
|
118
|
|
}
|
119
|
|
FileInputStream in = new FileInputStream(inputFile);
|
120
|
|
return FileUtil.readFile(in);
|
121
|
|
} else {
|
122
|
|
String absolutePath = util.getDirection(relativePath, isSdcard);
|
123
|
|
return FileUtil.readFile(absolutePath);
|
124
|
|
}
|
125
|
|
}
|
126
|
106
|
|
127
|
107
|
/**
|
128
|
108
|
* 追加指定文件
|
|
@ -149,22 +129,13 @@ public class MobileFile extends Plugin{
|
149
|
129
|
}
|
150
|
130
|
|
151
|
131
|
public void writeFile(String content, String relativePath, boolean isSdcard, boolean append) throws Exception {
|
152
|
|
if (!isSdcard) {
|
153
|
|
File outputFile = new File(context.getFilesDir(),relativePath);
|
154
|
|
if(!outputFile.getParentFile().exists()){
|
155
|
|
outputFile.getParentFile().mkdir();
|
156
|
|
}
|
157
|
|
OutputStream out = new FileOutputStream(outputFile,append);
|
158
|
|
FileUtil.writeFile(content, out);
|
159
|
|
} else {
|
160
|
|
String absolutePath = util.getDirection(relativePath, isSdcard);
|
161
|
|
File file = new File(absolutePath);
|
162
|
|
String parentPath = file.getParent();
|
163
|
|
if (!FileUtil.check(parentPath)) {
|
164
|
|
FileUtil.createDir(parentPath);
|
165
|
|
}
|
166
|
|
FileUtil.writeFile(content, absolutePath, append);
|
|
132
|
String absolutePath = util.getDirection(relativePath, isSdcard);
|
|
133
|
File file = new File(absolutePath);
|
|
134
|
String parentPath = file.getParent();
|
|
135
|
if (!FileUtil.check(parentPath)) {
|
|
136
|
FileUtil.createDir(parentPath);
|
167
|
137
|
}
|
|
138
|
FileUtil.writeFile(content, absolutePath, append);
|
168
|
139
|
}
|
169
|
140
|
public void getRelativePath(JSONArray params) throws Exception{
|
170
|
141
|
String fileName = params.getString(0); //相对路径参数
|