📄 example8_2.java
字号:
/* 读写图像文件 */
import javax.swing.JOptionPane;
import java.io.*;
class FileRW
{
int bytes;
byte buffer[ ] = new byte[65560];
FileInputStream fileInput;
FileOutputStream fileOutput;
FileRW()
{
takeimg();
loadimg();
JOptionPane.showMessageDialog(null,"文件复制并更名成功!\n文件大小为:"+bytes);
System.exit(0); //退出程序
}
//读取图像文件a.jpg
public void takeimg()
{
try {
File file=new File("a.jpg");
fileInput = new FileInputStream(file);
bytes = fileInput.read(buffer,0,65560);
} catch(IOException ei) { System.out.println(ei); }
}
//写入到b.jpg
public void loadimg()
{
try {
fileOutput = new FileOutputStream("b.jpg");
fileOutput.write(buffer, 0, bytes) ;
} catch(IOException eo) { System.out.println(eo); }
}
}
public class Example8_2
{
public static void main(String[] args)
{ new FileRW(); }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -