<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 />