fileaccess.java
来自「j2me的基于http协议的断点续传。支持多线程的断点续传。」· Java 代码 · 共 45 行
JAVA
45 行
/**
* FileAccess.java
*/
package NetFox;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
public class FileAccess
{
FileConnection fConn = null;
OutputStream savedFile = null;
private FileAccess() {
}
public FileAccess(String sName, long nPos) throws IOException {
Utility.log("try to create or resume file: [" + sName + "]");
fConn = Utility.createFileConn(sName);
if (!fConn.exists()) {
fConn.create();
}
fConn.truncate(nPos + 1);
savedFile = fConn.openOutputStream(nPos);
}
public void close() throws Exception {
if (null != savedFile) savedFile.close();
if (null != fConn) fConn.close();
}
public synchronized int write(byte[] b,int nStart,int nLen) {
int n = -1;
try {
savedFile.write(b, nStart, nLen);
n = nLen;
} catch(IOException e) {
Utility.log(e.getMessage());
}
return n;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?