/*
*
* Copyright (c) 2007, Sun Microsystems, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Sun Microsystems nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package example.fc;
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* Demonstration MIDlet for File Connection API. This MIDlet implements simple
* file browser for the filesystem available to the J2ME applications.
*
*/
public class FileBrowser extends MIDlet implements CommandListener {
private static final String[] attrList = { "Read", "Write", "Hidden" };
private static final String[] typeList = { "Regular File", "Directory" };
private static final String[] monthList =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
/* special string denotes upper directory */
private static final String UP_DIRECTORY = "..";
/* special string that denotes upper directory accessible by this browser.
* this virtual directory contains all roots.
*/
private static final String MEGA_ROOT = "/";
/* separator string as defined by FC specification */
private static final String SEP_STR = "/";
/* separator character as defined by FC specification */
private static final char SEP = '/';
private String currDirName;
private Command view = new Command("View", Command.ITEM, 1);
private Command creat = new Command("New", Command.ITEM, 2);
//add delete file functionality
private Command delete = new Command("Delete", Command.ITEM, 3);
private Command creatOK = new Command("OK", Command.OK, 1);
private Command prop = new Command("Properties", Command.ITEM, 2);
private Command back = new Command("Back", Command.BACK, 2);
private Command exit = new Command("Exit", Command.EXIT, 3);
private TextField nameInput; // Input field for new file name
private ChoiceGroup typeInput; // Input field for file type (regular/dir)
private Image dirIcon;
private Image fileIcon;
private Image[] iconList;
public FileBrowser() {
currDirName = MEGA_ROOT;
try {
dirIcon = Image.createImage("/icons/doc.png");
} catch (IOException e) {
dirIcon = null;
}
try {
fileIcon = Image.createImage("/icons/txt.png");
} catch (IOException e) {
fileIcon = null;
}
iconList = new Image[] { fileIcon, dirIcon };
}
public void startApp() {
try {
showCurrDir();
} catch (SecurityException e) {
Alert alert =
new Alert("Error", "You are not authorized to access the restricted API", null,
AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
Form form = new Form("Cannot access FileConnection");
form.append(new StringItem(null,
"You cannot run this MIDlet with the current permissions. " +
"Sign the MIDlet suite, or run it in a different security domain"));
form.addCommand(exit);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(alert, form);
} catch (Exception e) {
e.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean cond) {
notifyDestroyed();
}
public void commandAction(Command c, Displayable d) {
if (c == view) {
List curr = (List)d;
final String currFile = curr.getString(curr.getSelectedIndex());
new Thread(new Runnable() {
public void run() {
if (currFile.endsWith(SEP_STR) || currFile.equals(UP_DIRECTORY)) {
traverseDirectory(currFile);
} else {
// Show file contents
showFile(currFile);
}
}
}).start();
} else if (c == prop) {
List curr = (List)d;
String currFile = curr.getString(curr.getSelectedIndex());
showProperties(currFile);
} else if (c == creat) {
createFile();
} else if (c == creatOK) {
String newName = nameInput.getString();
if ((newName == null) || newName.equals("")) {
Alert alert =
new Alert("Error!", "File Name is empty. Please provide file name", null,
AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(alert);
} else {
// Create file in a separate thread and disable all commands
// except for "exit"
executeCreateFile(newName, typeInput.getSelectedIndex() != 0);
Display.getDisplay(this).getCurrent().removeCommand(creatOK);
Display.getDisplay(this).getCurrent().removeCommand(back);
}
} else if (c == back) {
showCurrDir();
} else if (c == exit) {
destroyApp(false);
} else if (c == delete) {
List curr = (List)d;
String currFile = curr.getString(curr.getSelectedIndex());
executeDelete(currFile);
}
}
void delete(String currFile) {
if (!currFile.equals(UP_DIRECTORY)) {
if (currFile.endsWith(SEP_STR)) {
checkDeleteFolder(currFile);
} else {
deleteFile(currFile);
showCurrDir();
}
} else {
Alert cantDeleteFolder =
new Alert("Error!",
"Can not delete The up-directory (..) " + "symbol! not a real folder", null,
AlertType.ERROR);
cantDeleteFolder.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(cantDeleteFolder);
}
}
private void executeDelete(String currFile) {
final String file = currFile;
new Thread(new Runnable() {
public void run() {
delete(file);
}
}).start();
}
FileDemo1.rar_PIM_话单
版权申诉
162 浏览量
2022-09-19
14:22:19
上传
评论
收藏 33KB RAR 举报
邓凌佳
- 粉丝: 65
- 资源: 1万+
最新资源
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈