Win7系统下,IE8浏览器,jre1.6,Applet可以运行,
但是不能读写本地文件,怎么解决?
Applet win7权限 Applet?读写本地文件 JNDI IE8?Applet
------解决方案--------------------
Applet现在还在用啊?。。
------解决方案--------------------
实现 java.security.PrivilegedAction 就可以了。
例子:
/**
* added by Defonds
* @param filesInfo
* File Name1
------解决方案--------------------
File Flag Public1
------解决方案--------------------
File Document Language1
------解决方案--------------------
File Description1
------解决方案--------------------
File Operating System1
------解决方案--------------------
File Store1
------解决方案--------------------
File Title1
------解决方案--------------------
File Flag Exp1
*/
public void addFileInfomation(String filesInfo,String directoryInfo,String formatInfo){
System.out.println("the file info str gived to applet is:" + filesInfo);
String fileName = "",fileFlagPublic = "",fileDocomentLanguage = "",fileDescription = "",
fileOperatingSystem = "",fileStore = "",fileTitle = "",fileFlagExp = "";
String[] filesInfoArr = filesInfo.split("
------解决方案--------------------
");
if(filesInfoArr.length > 0){
fileName = filesInfoArr[0];
fileFlagPublic = filesInfoArr[1];
fileDocomentLanguage = filesInfoArr[2];
fileDescription = filesInfoArr[3];
fileOperatingSystem = filesInfoArr[4];
fileStore = filesInfoArr[5];
fileTitle = filesInfoArr[6];
fileFlagExp = filesInfoArr[7];
}
java.io.File checkinFile = new java.io.File(directoryInfo);
FileInfo file = new FileInfo(checkinFile);
file.setFileStore(fileStore);
file.setFormat(formatInfo);
file.setFileFlagPublic(fileFlagPublic);
file.setFileFlagEXP(fileFlagExp);
file.setFileDocumentLanguage(fileDocomentLanguage);
System.out.println("applet-filename=" + file.getFileName());
addFile(file);
System.out.println("a file added successfully!");
}
/**
* @added by Defonds
* @param directoryStr
* D:/tmp/tmp/AppDevGuide1071.pdf@@@D:/tmp/tmp/AppDevGuide1072.pdf@@@...
* @return
* D:/tmp/tmp/AppDevGuide1071.pdf@@@D:/tmp/tmp/AppDevGuide1072.pdf...
* @note
* only return the directories which are valid
*/
public synchronized String directoryValid(String directoryStr){
System.out.println("the file directory info give to applet is:" + directoryStr);
_fileValidStr = directoryStr;
FileValidRunner runner = new FileValidRunner();
AccessController.doPrivileged(runner);
System.out.println("applet return value is:" + _fileValidStrRe);
return _fileValidStrRe;
}
/**
* @author defonds
*/
class FileValidRunner implements PrivilegedAction {
public Object run() {
String[] direArrs = _fileValidStr.split("@@@");
if(direArrs.length > 0){
for(int i = 0;i < direArrs.length;i ++){
String tmpName = direArrs[i];
java.io.File tmpFile = new java.io.File(tmpName);
if(tmpFile.exists()){//only return the directories which are invalid
if(_fileValidStrRe.equals("")){//the first one
_fileValidStrRe = tmpName;
}else{//not the first one
_fileValidStrRe += "@@@" + tmpFile;
}
}
}
}
return null;
}
FileValidRunner() {
}
}
参考:
js 动态调用 applet 内的方法