日期:2014-05-20 浏览次数:20812 次
public class SwitchWriter
{
public static void main(String[] args) throws IOException
{
InputStream input = new FileInputStream(new File("D:\\杂乱\\头像.jpg"));
StringBuffer buff = new StringBuffer();
byte[] img = new byte[1024];
while (input.read(img) != -1)
{
buff.append(new String(img));
}
//生成图片失败,这时怎么回事啊?
OutputStreamWriter output = new OutputStreamWriter(
new FileOutputStream("D:\\杂乱\\头像_new.jpg"));
String str = buff.toString();
output.write(str, 0, str.length());
output.flush();
output.close();
input.close();
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class SwitchWriter {
public static void main(String[] args) {
FileInputStream input = null;
FileOutputStream output = null;
try {
input = new FileInputStream(new File("D:\\杂乱\\头像.jpg"));
output = new FileOutputStream("D:\\杂乱\\头像_new.jpg");
int a;
while ((a = input.read()) != -1) {
output.write(a);
}
output.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class SwitchWriter {
public static void main(String[] args) {
try {
copy("E:\\login_icon.png", "E:\\test.png");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 复制文件,使用字节流
*
* @param sourcePath
* @param targetPath
* @throws IOException
*/
public static void copy(String sourcePath, String targetPath)
throws IOException {
FileInputStream fis = new FileInputStream(sourcePath);