/*
***************************************************************************
*
* Read and write arrays of various data types.
*
***************************************************************************
*/
import java.io.*;
public class ArrayIO {
public static void readByteArray(String fname, int array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
FileInputStream fin= new FileInputStream(file);
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
array[i][j] = (int)(0xFF & fin.read()); // Unsigned char to integer
fin.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
public static void writeByteArray(String fname, int array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
FileOutputStream fout = new FileOutputStream(file);
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
fout.write((byte)(0xFF & array[i][j])); // Integer to unsigned char
fout.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
public static void readIntArray(String fname, int array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
DataInputStream fin = new DataInputStream(new FileInputStream(file));
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
array[i][j] = fin.readInt();
fin.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
public static void writeIntArray(String fname, int array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
DataOutputStream fout = new DataOutputStream(new FileOutputStream(file));
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
fout.writeInt(array[i][j]);
fout.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
public static void readFloatArray(String fname, float array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
DataInputStream fin = new DataInputStream(new FileInputStream(file));
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
array[i][j] = fin.readFloat();
fin.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
public static void writeFloatArray(String fname, float array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
DataOutputStream fout = new DataOutputStream(new FileOutputStream(file));
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
fout.writeFloat(array[i][j]);
fout.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
public static void readDoubleArray(String fname, double array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
DataInputStream fin = new DataInputStream(new FileInputStream(file));
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
array[i][j] = fin.readDouble();
fin.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
public static void writeDoubleArray(String fname, double array[][],
int nrows, int ncols) {
try {
File file = new File(fname);
DataOutputStream fout = new DataOutputStream(new FileOutputStream(file));
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
fout.writeDouble(array[i][j]);
fout.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
} // end class ArrayIO
java图像处理源码
4星 · 超过85%的资源 需积分: 3 35 浏览量
2009-01-01
13:39:45
上传
评论
收藏 25KB RAR 举报
zhulei420
- 粉丝: 0
- 资源: 6
最新资源
- Installing Anaconda and PyCharm - Marco Sammon
- git使用文档(一步一步教你使用Git仓库管理代码)
- 进制转换(通用版).cpp
- linux实践之从DistroWatch排名第三的EndeavourOS转到排名第五的Manjaro工作机迁移
- Discuz模板+资讯博客课程干货+商业版(GBK+UTF)
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本123.0.6292.0)
- RB308A-SOT23-5 单节锂电池保护IC 深圳市可芯电子有限公司.pdf
- Ubuntu下安装JDK
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本123.0.6291.0)
- Android基础之用Eclipse建立工程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈