请大家指点,我这个图片复制程序有问题,
package test;import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;public class TestD
{ /**
* @param args
*/
public static void main(String[] args)
{ File file = new File("C:\\Documents and Settings\\Administrator\\桌面\\images\\img\\all.jpg");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int temp = 0;
InputStream is = null;
OutputStream os = null;
try
{
is = new FileInputStream(file);
os = new FileOutputStream(new File("C:\\Documents and Settings\\Administrator\\桌面\\彩信搞搞\\XXXXX.jpg"));
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} try
{
while ((temp = is.read()) != -1)
{
bos.write(temp);
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(bos.toString()); try
{
os.write(bos.toByteArray());
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
os.close();
is.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} }}
package test;import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;public class TestD
{ /**
* @param args
*/
public static void main(String[] args)
{ File file = new File("C:\\Documents and Settings\\Administrator\\桌面\\images\\img\\all.jpg");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int temp = 0;
InputStream is = null;
OutputStream os = null;
try
{
is = new FileInputStream(file);
os = new FileOutputStream(new File("C:\\Documents and Settings\\Administrator\\桌面\\彩信搞搞\\XXXXX.jpg"));
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} try
{
while ((temp = is.read()) != -1)
{
bos.write(temp);
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(bos.toString()); try
{
os.write(bos.toByteArray());
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
os.close();
is.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} }}
*
* @author Administrator
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
File file = new File("C:\\Documents and Settings\\Administrator\\桌面\\1.jpg");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int temp = 0;
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(file);
//文件不存在
File of = new File("C:\\Documents and Settings\\Administrator\\桌面\\彩信搞搞\\XXXXX.jpg");
try {
if(!of.exists()||!of.createNewFile()){
System.exit(0);
}
} catch (IOException ex) {
ex.printStackTrace();
System.exit(0);
}
os = new FileOutputStream(of);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while ((temp = is.read()) != -1) {
bos.write(temp);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(bos.toString());
try {
os.write(bos.toByteArray());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
os.close();
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
is = new FileInputStream(file);
File of = new File("C:\\Documents and Settings\\Administrator\\桌面\\彩信搞搞\\XXXXX.jpg");
try {
if(of.exists()||of.getParentFile().exists()||of.getParentFile().mkdirs());
if(!of.isFile()&&!of.createNewFile())
System.exit(0);
} catch (IOException ex) {
ex.printStackTrace();
System.exit(0);
}
os = new FileOutputStream(of);
package IO;import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* test.getBytes("iso8859-1"))
* 用OutputStream和InputStream实现文件的写入和读取(字节的写入和读取)
*
*/
public class InAndOut {
String path="e:\\abc.txt";
public static void main(String[] args) {
InAndOut io=new InAndOut ();
io.write("我是邪恶少年!");
io.read();
}
public void write(String content)
{
File f=new File (path);
boolean add=true;//是否写入
try {
if (f.exists()==false) {
f.createNewFile();
FileOutputStream os=new FileOutputStream (f);//不用判断是否写入
//FileOutputStream os=new FileOutputStream (f,add);//要判断是否写入
os.write(content.getBytes());
os.flush();
os.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void read()
{
try {
InputStream is=new FileInputStream(path);
//BufferedInputStream bis=new BufferedInputStream(new FileInputStream(path));
int temp=0;
String test="";
try {
while ((temp=is.read())!=-1) {
test+=(char)temp;
}
System.out.println(new String (test.getBytes("iso8859-1")));//会出现乱码
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}