请大家指点,我这个图片复制程序有问题,
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();
} }}
解决方案 »
- 求类似QQ空间日志的编辑器
- java与xml构建配置文件
- 请教一个算法(将任意字符串转换为1-100的数字)
- 一个最简单的java问题
- 高手救命,关于TABLE的数据
- 请教问题,代码中有 import javax.microedition.io.*; 编译成功后,可以在pc机上运行吗
- 有关在button中增加图片的简单问题,在线等待
- 点击JB中的Database组件的conection属性的时候(准备连接sql server),怎么会没有反应?
- jbuilder7 为什么无法注册
- 我是编译通过了,但是运行时却有这样的错误,怎么回事啊?
- 连接sql server 2005出现异常
- 文本编辑器怎样显示行号???
*
* @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();
}
}
}