File inlog = new File("D:/Water lilies.jpg");
File charFile = new File("D:/Water lilies backup.jpg");
if(charFile.exists()) charFile.delete();
charFile.createNewFile();
FileReader fr = new FileReader(inlog);
FileWriter fw = new FileWriter(charFile);
BufferedReader br = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
int bbb = fr.read();
while(bbb != -1){
fw.write(bbb);
bbb = fr.read();
}
fw.flush();为什么复制出来的图片,上面全都出现了很多红点点呢?
File charFile = new File("D:/Water lilies backup.jpg");
if(charFile.exists()) charFile.delete();
charFile.createNewFile();
FileReader fr = new FileReader(inlog);
FileWriter fw = new FileWriter(charFile);
BufferedReader br = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
int bbb = fr.read();
while(bbb != -1){
fw.write(bbb);
bbb = fr.read();
}
fw.flush();为什么复制出来的图片,上面全都出现了很多红点点呢?
解决方案 »
- 求解ArrayList<UserGameInfo>转化为xml文件输出?
- jPanel里面的带icon的label为什么不显示
- DocumentListener.changedUpdate() 在何时被触发
- 有没有在北京,参加过或者即将参加中讯集团的笔试的哥们?
- 救命的,如何用java语言来修改oracle中的时间字段
- 超级变态的问题,请各位高手帮帮忙~~~谢谢!!!!!!!!!!!
- 如何调用Oracle的存储过程
- 如何隐藏JTable中的某一列?
- 我导入一个已经写好的maven项目,这个项目是可以运行的,我导入后启动就报监听器错误
- 数据模型设计??????
- 去重复字符的问题(求完整代码!),急啊。
- 220.10.5.19如何自动补0
static final int BUFF_SIZE = 100000;
static final byte[] buffer = new byte[BUFF_SIZE];
public static void main(String[] args) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream("D:/1.jpg");
out = new FileOutputStream("D:/2.jpg");
while (true) {
synchronized (buffer) {
int amountRead = in.read(buffer);
if (amountRead == -1) {
break;
}
out.write(buffer, 0, amountRead);
}
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;public class FileCopy { public static void main(String[] args) throws IOException {
long result = ioCopy("e:/灰太狼.gif", "e:/灰太狼_bak.gif");
System.out.println(result);
} /**
* NIO 文件复制
* @param srcName
* @param destName
* @return 复制的字节数量
* @throws IOException
* @author frankiegao123
* 2010-4-29 下午01:57:01
*/
public static long nioCopy(String srcName, String destName) throws IOException {
return nioCopy(new File(srcName), new File(destName));
} public static long nioCopy(File src, File dest) throws IOException {
FileChannel srcChannel = null;
FileChannel destChannel = null;
long result = -1;
try {
srcChannel = new FileInputStream(src).getChannel();
destChannel = new FileOutputStream(dest).getChannel();
result = srcChannel.transferTo(0, src.length(), destChannel);
} finally {
close(srcChannel);
close(destChannel);
}
return result;
} /**
* 传统 IO 文件复制
* @param srcName
* @param destName
* @return 复制的字节数量
* @throws IOException
* @author frankiegao123
* 2010-4-29 下午01:57:08
*/
public static long ioCopy(String srcName, String destName) throws IOException {
return ioCopy(new File(srcName), new File(destName));
} public static long ioCopy(File src, File dest) throws IOException {
BufferedInputStream in = null;
BufferedOutputStream out = null;
long result = -1;
try {
in = new BufferedInputStream(new FileInputStream(src));
out = new BufferedOutputStream(new FileOutputStream(dest));
byte[] bys = new byte[8 * 1024];
long tmpResult = 0;
for (int n = -1; (n = in.read(bys)) > -1; tmpResult += n) {
out.write(bys, 0, n);
}
result = tmpResult;
} finally {
close(in);
close(out);
}
return result;
} private static void close(Closeable io) {
if (io != null) {
try {
io.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}