📄 fileaction.java
字号:
/*****************************************************************************
Description: FileAction
* The FileAction class is used for fileSystem funtionality such as list Directory content,
* save file, load image and delete file/directory.
* The object that creates fileAction object has to implement the FileActionInvoker iterface since
* it takes a reference to a FileActionInvoker to its constructor.
* The fileAction object calls methods of the FileActionInvoker when it is done performing the
* filesystemfunctionality
*
Created By: Johan Kateby
@file FileAction.java
COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004.
The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
The use of the software is subject to the terms of the end-user license
agreement which accompanies or is included with the software. The software is
provided "as is" and Sony Ericsson specifically disclaim any warranty or
condition whatsoever regarding merchantability or fitness for a specific
purpose, title or non-infringement. No warranty of any kind is made in
relation to the condition, suitability, availability, accuracy, reliability,
merchantability and/or non-infringement of the software provided herein.
*****************************************************************************/
import java.util.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.lcdui.*;
public class FileAction {
// The object to be notified when a file system operation has finished
FileActionInvoker browser;
public FileAction(FileActionInvoker browser)
{
this.browser=browser;
}
// get the content of a directory and send the content to the fileActionInvoker
// by callig the method browser.updateDirList
public synchronized void getDirContent(String currentDir)
{
Enumeration CurrentDirEnum=null ;
FileConnection currDirFC=null;
System.out.println("FileThread.run");
boolean isRoot=false;
try{
if(currentDir.equals("/"))
{
CurrentDirEnum = FileSystemRegistry.listRoots();
isRoot=true;
}
else
{
currDirFC = (FileConnection)Connector.open("file://"+currentDir);
if(currDirFC!=null)
CurrentDirEnum = currDirFC.list();
}
}
catch(SecurityException e){
System.out.println("Security exception");
CurrentDirEnum=null ;
}
catch(Exception ex){
System.out.println("FileSystemThread.run- Exception:"+ex.toString());
}
finally
{
try
{ if(currDirFC!=null)
currDirFC.close();
}
catch(Exception e)
{
System.out.println("FileSystemThread.run Exception "+e.toString());
}
currDirFC=null;
browser.updateDirList(CurrentDirEnum, isRoot);
}
}
// Saving the file and sending a message of the status to the FileActionInvoker by calling its method
// browser.fileSavedComplete
public synchronized void saveFile(String fileURL, byte [] data)
{
OutputStream os;
FileConnection currDirFC=null;
try
{
FileConnection fileConn =(FileConnection)Connector.open(fileURL);
if(fileConn.exists())
{
browser.fileSavedComplete("File Already exists");
return;
}
fileConn.create();
os = fileConn.openOutputStream();
for(int i=0; i<data.length;i++)
{
os.write(data[i]);
}
fileConn.close();
os.close();
}catch(Exception e){
browser.fileSavedComplete("ERROR DURING SAVE OPERATION");
return;
}
browser.fileSavedComplete("file saved");
}
// Load the image and send to the FileActionInvoker by caklling its method
// browser.ImageReceived
public void getImage(String fileURL)
{
Image image=null;
try
{
FileConnection fileConn =(FileConnection)Connector.open(fileURL);
InputStream fis = fileConn.openInputStream();
image = Image.createImage(fis);
fis.close();
fileConn.close();
}
catch (Exception e)
{
System.out.println("FileAction.getImage:"+e.toString());
browser.ImageReceived(null);
}
browser.ImageReceived(image);
}
// Deleint a file or directory
public synchronized void delete(String fileURL)
{
try
{
FileConnection fileConn =(FileConnection)Connector.open(fileURL);
fileConn.delete();
fileConn.close();
}
catch(Exception e){System.out.println("FileAction.delete:"+e.toString());}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -