本文整理汇总了Java中javax.microedition.io.file.FileConnection.delete方法的典型用法代码示例。如果您正苦于以下问题:Java FileConnection.delete方法的具体用法?Java FileConnection.delete怎么用?Java FileConnection.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.file.FileConnection
的用法示例。
在下文中一共展示了FileConnection.delete方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remove
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public void remove() throws IOException {
FileConnection con = connector();
//TODO: this really needs to be written better, but
//for now avoiding deadlock is better than ensuring
//thread safety
//Take a lock on the connection so that nothing tries
//to access it while this happens
synchronized(con) {
con.delete();
con.close();
}
//Take a lock on the connections so that
//nothing can retrieve the connection
synchronized(connections) {
//Remove the local connection now that it's
//closed.
clearReferenceConnection(getLocalURI());
}
}
示例2: generateData
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
void generateData() throws IOException {
String str = "";
String part = "abcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZabcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZ";
for (int i = 0; i < 2000; i++) {
str += part;
}
cbuf = new char[str.length()];
cbufReader = new char[cbuf.length];
str.getChars(0, str.length(), cbuf, 0);
String dirPath = System.getProperty("fileconn.dir.private");
file = (FileConnection)Connector.open(dirPath + "test");
if (file.exists()) {
file.delete();
}
file.create();
}
示例3: test0001
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests delete() on a file
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Deleting file");
conn.delete();
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists == false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests delete() on a file", passed);
}
示例4: test0002
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests delete() on a directory
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
try {
addOperationDesc("Creating directory: " + conn.getURL());
ensureDirExists(conn);
addOperationDesc("Deleting directory");
conn.delete();
boolean exists = conn.exists();
addOperationDesc("exists() returned " + exists);
passed = exists ==false;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests delete() on a file", passed);
}
示例5: runBenchmark
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
void runBenchmark() {
try {
long start;
String dirPath = System.getProperty("fileconn.dir.private");
FileConnection file = (FileConnection)Connector.open(dirPath + "test");
if (file.exists()) {
file.delete();
}
file.create();
OutputStream fileOut = file.openOutputStream();
start = JVM.monotonicTimeMillis();
writeUTF(fileOut);
System.out.println("DataOutputStream::writeUTF in file: " + (JVM.monotonicTimeMillis() - start));
InputStream fileIn = file.openInputStream();
start = JVM.monotonicTimeMillis();
readUTF(fileIn);
System.out.println("DataInputStream::readUTF from file: " + (JVM.monotonicTimeMillis() - start));
file.close();
} catch (IOException e) {
System.out.println("Unexpected exception: " + e);
e.printStackTrace();
}
}
示例6: delete
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public static boolean delete(String path) {
try {
FileConnection fc = (FileConnection) Connector.open(path, Connector.READ_WRITE);
fc.delete();
fc.close();
return true;
} catch (Exception e) {
return false;
}
}
示例7: runBenchmark
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
void runBenchmark() {
try {
long start, time = 0;
client = (LocalMessageProtocolConnection)Connector.open("localmsg://nokia.image-processing");
DataEncoder dataEncoder = new DataEncoder("Conv-BEB");
dataEncoder.putStart(14, "event");
dataEncoder.put(13, "name", "Common");
dataEncoder.putStart(14, "message");
dataEncoder.put(13, "name", "ProtocolVersion");
dataEncoder.put(10, "version", "1.[0-10]");
dataEncoder.putEnd(14, "message");
dataEncoder.putEnd(14, "event");
byte[] sendData = dataEncoder.getData();
client.send(sendData, 0, sendData.length);
LocalMessageProtocolMessage msg = client.newMessage(null);
client.receive(msg);
FileConnection originalImage = (FileConnection)Connector.open("file:////test.jpg", Connector.READ_WRITE);
if (!originalImage.exists()) {
originalImage.create();
}
OutputStream os = originalImage.openDataOutputStream();
InputStream is = getClass().getResourceAsStream("/org/mozilla/io/test.jpg");
os.write(TestUtils.read(is));
os.close();
MemorySampler.sampleMemory("Memory before nokia.image-processing benchmark");
for (int i = 0; i < 1000; i++) {
start = JVM.monotonicTimeMillis();
String path = scaleImage();
time += JVM.monotonicTimeMillis() - start;
FileConnection file = (FileConnection)Connector.open(path);
file.delete();
file.close();
}
System.out.println("scaleImage: " + time);
MemorySampler.sampleMemory("Memory after nokia.image-processing benchmark");
originalImage.delete();
originalImage.close();
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: startApp
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public void startApp() {
if (alreadyStarted) {
return;
}
alreadyStarted = true;
if (shouldStop()) {
System.out.println("Test finished");
return;
}
try {
Display.getDisplay(this).setCurrent(new TestCanvas());
// Wait MIDlet to become the foreground MIDlet
synchronized (paintedLock) {
while (!painted) {
paintedLock.wait();
}
}
ContentHandlerServer chServer = Registry.getServer(getClass().getName());
// Check if the MIDlet has been invoked
Invocation invoc = chServer.getRequest(false);
if (invoc == null) {
System.out.println("Invocation is null");
return;
}
String shareAction = invoc.getAction();
System.out.println("Invocation action: " + shareAction);
String[] shareArgs = invoc.getArgs();
for (int i = 0; i < shareArgs.length; i++) {
System.out.println("Invocation args[" + i + "]: " + shareArgs[i]);
}
FileConnection image = (FileConnection)Connector.open(shareArgs[0].substring(4), Connector.READ_WRITE);
if (!image.exists()) {
System.out.println("Image doesn't exist");
} else {
System.out.println("Image exists");
image.delete();
}
invoc.setArgs(null);
chServer.finish(invoc, Invocation.INITIATED);
} catch (Exception e) {
System.out.println("Unexpected exception: " + e);
}
// Test that the Content Handler code works also if the MIDlet is already running.
sendShareMessage();
}
示例9: test
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public void test(TestHarness th) {
try {
FileConnection file = (FileConnection)Connector.open("file:////prova");
if (file.exists()) {
file.delete();
}
file.create();
RandomAccessStream ras = new RandomAccessStream();
ras.connect("prova", Connector.READ_WRITE);
OutputStream out = ras.openOutputStream();
testWrite(th, out);
out.close();
ras.setPosition(0);
InputStream in = ras.openInputStream();
testRead(th, in);
in.close();
ras.disconnect();
file.delete();
th.check(!file.exists());
file.create();
out = file.openOutputStream();
testWrite(th, out);
out.close();
in = file.openInputStream();
testRead(th, in);
in.close();
file.delete();
file.close();
} catch (Exception e) {
th.fail("Unexpected exception: " + e);
e.printStackTrace();
}
}
示例10: cleanup
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
void cleanup() throws IOException {
FileConnection file = (FileConnection)Connector.open("file:////afile");
file.delete();
file.close();
}