我想x
一次从文件读取字节(例如“ testFile.raw”),然后将那些字节输出到另一个文件。
例如:
read 20 bytes from testFile.raw -> dump into outputfile.jpg
...repeat until done...
这可能吗?
这是一个使用大小为20的字节数组的示例:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class FileInputOutputExample {
public static void main(String[] args) throws Exception {
try{
byte[] b = new byte[20];
InputStream is = new FileInputStream("in.txt");
OutputStream os = new FileOutputStream("out.txt");
int readBytes = 0;
while ((readBytes = is.read(b)) != -1) {
os.write(b, 0, readBytes);
}
is.close();
os.close();
}catch(IOException ioe){
System.out.println("Error "+ioe.getMessage());
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句