fileaccess.java

来自「关于多线程下载的功能实现源代码」· Java 代码 · 共 36 行

JAVA
36
字号
package group.common.globalget.model;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.Serializable;

public class FileAccess implements Serializable {

	RandomAccessFile oSavedFile;

	long nPos;

	public FileAccess() throws IOException {
		this("", 0);
	}

	public FileAccess(String sName, long nPos) throws IOException {
		oSavedFile = new RandomAccessFile(sName, "rw");
		this.nPos = nPos;
		oSavedFile.seek(nPos);
	}

	public synchronized int write(byte[] b, int nStart, int nLen) {
		int n = -1;
		try {
			oSavedFile.write(b, nStart, nLen);
			n = nLen;
		} catch (IOException e) {
			e.printStackTrace();
		}

		return n;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?