本文整理汇总了Java中javax.microedition.io.file.FileConnection.truncate方法的典型用法代码示例。如果您正苦于以下问题:Java FileConnection.truncate方法的具体用法?Java FileConnection.truncate怎么用?Java FileConnection.truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.file.FileConnection
的用法示例。
在下文中一共展示了FileConnection.truncate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test0001
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests truncate()
*/
public void test0001() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Writing 8 bytes");
os = conn.openOutputStream();
os.write(new byte[8]);
os.close();
os = null;
addOperationDesc("Truncating at byte 1");
conn.truncate(1);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==1;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests truncate()", passed);
}
示例2: test0002
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests truncate() where byteOffset is greater than the current end of file
*/
public void test0002() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Writing 8 bytes");
os = conn.openOutputStream();
os.write(new byte[8]);
os.close();
os = null;
addOperationDesc("Truncating at byte 10");
conn.truncate(10);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==8;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests truncate() where byteOffset is greater than the current end of file", passed);
}
示例3: test0011
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests if a file is truncated properly even if an open outputstream is not explicitly flushed by the user
*/
public void test0011() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
OutputStream os = null;
try {
addOperationDesc("Creating file: " + conn.getURL());
ensureFileExists(conn);
addOperationDesc("Writing 8 bytes");
os = conn.openOutputStream();
os.write(new byte[8]);
addOperationDesc("Truncating at byte 7");
conn.truncate(7);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==7;
} finally {
if (os != null) os.close();
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if a file is truncated properly even if an open outputstream is not explicitly flushed by the user", passed);
}