IO
来源:互联网 发布:淘宝网站源码 编辑:程序博客网 时间:2024/06/01 22:16
<pre class="java" name="code">public class ReadFile
{
private final String pathname;
private final File file;
private FileInputStream fis;
private int filePoint=0;
ReadFile(String pathname)
throws FileNotFoundException
{
this.pathname = pathname;
this.file = new File(pathname);
}
public void open()
throws FileNotFoundException
{
this.fis = new FileInputStream(file);
}
public int read(byte[] b)
throws IOException
{
return read(b, 0, b.length);
}
private int getFilePoint( )
{
return filePoint;
}
public int read(byte[] b, int off, int len)
throws IOException
{
return read(b, off, len,1);
}
public int read(byte[] b, int off, int len, int startReadLocation)
throws IOException
{
int i = -1;
if (parameterIsOk(b, off, len, startReadLocation) == false)
{throw new IndexOutOfBoundsException();
}
else
{
int c = fis.read();
if (c == -1)
{
return -1;
}
i = 1;
try
{
for (; i < startReadLocation; i++)
{
c = fis.read();
if (c == -1)
{
break;
}
}
i = 0;
for (; i < len ; i++)
{
b[off + i] = (byte)c;
c = fis.read();
if (c == -1)
{
break;
}
}
}
catch (IOException e)
{
}
}
filePoint=startReadLocation+len;
return i;
}
public boolean parameterIsOk(byte[] b, int off, int len, int startReadLocation)
{
boolean parameterIsOk = false;
if (fis == null || b == null)
{
throw new NullPointerException();
}
else if (off < 0 || len <= 0 || len > b.length - off)
{
throw new IndexOutOfBoundsException();
}
else
{
parameterIsOk = true;
}
return parameterIsOk;
}
public void close()
throws IOException
{
fis.close();
}</pre>
<br />
<br />
{
private final String pathname;
private final File file;
private FileInputStream fis;
private int filePoint=0;
ReadFile(String pathname)
throws FileNotFoundException
{
this.pathname = pathname;
this.file = new File(pathname);
}
public void open()
throws FileNotFoundException
{
this.fis = new FileInputStream(file);
}
public int read(byte[] b)
throws IOException
{
return read(b, 0, b.length);
}
private int getFilePoint( )
{
return filePoint;
}
public int read(byte[] b, int off, int len)
throws IOException
{
return read(b, off, len,1);
}
public int read(byte[] b, int off, int len, int startReadLocation)
throws IOException
{
int i = -1;
if (parameterIsOk(b, off, len, startReadLocation) == false)
{throw new IndexOutOfBoundsException();
}
else
{
int c = fis.read();
if (c == -1)
{
return -1;
}
i = 1;
try
{
for (; i < startReadLocation; i++)
{
c = fis.read();
if (c == -1)
{
break;
}
}
i = 0;
for (; i < len ; i++)
{
b[off + i] = (byte)c;
c = fis.read();
if (c == -1)
{
break;
}
}
}
catch (IOException e)
{
}
}
filePoint=startReadLocation+len;
return i;
}
public boolean parameterIsOk(byte[] b, int off, int len, int startReadLocation)
{
boolean parameterIsOk = false;
if (fis == null || b == null)
{
throw new NullPointerException();
}
else if (off < 0 || len <= 0 || len > b.length - off)
{
throw new IndexOutOfBoundsException();
}
else
{
parameterIsOk = true;
}
return parameterIsOk;
}
public void close()
throws IOException
{
fis.close();
}</pre>
<br />
<br />
- IO
- IO
- io
- IO
- io
- IO
- io
- IO
- IO
- IO
- io
- IO
- IO
- IO
- IO
- IO
- IO
- IO
- Andorid APK反逆向解决方案:梆梆加固原理探寻【存档】
- 数据库复习1
- linux关闭防火墙
- 气象站的故事-观察者模式
- cocos2d-x 新建项目 Cannot open include file: 'cocos2d.h'
- IO
- 在 WCF 中使用高效的 BinaryFormatter 序列化
- linux下IPTABLES配置详解
- Javascript 检测键盘按键
- C#压缩图片
- jquery ztree
- 安装iptables防火墙
- JavaScript学习笔记(三十二) 经典继承模式二-借用构造方法
- 湿指纹识别技术 – 机遇与挑战并存