问题复制文件 [英] Problem copy file

查看:68
本文介绍了问题复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将文件复制到其他目的地。我的代码无法按预期工作。任何人都帮我。我收到此错误消息--->

java.io.FileNotFoundException:C :\Documents and Settings \XXXXXXX \ MyMy Documents(访问被拒绝)

在java.io.FileOutputStream.open(本机方法)

在java.io .FileOutputStream。< init>(FileOutputStream.j ava:179)

at java.io.FileOutputStream。< init>(FileOutputStream.j ava:131)

在test1.PilihFail $ Salin2.run(PilihFail.java:111)


代码是:

private int currentValue;


public void run(){


BufferedInputStream in = null;

BufferedOutputStream out = null;


尝试{

文件inFile =新文件(jtfOpen.getText()。trim());

in = new BufferedInputStream(new FileInputStream(inFi) le));


文件outFile =新文件(jtfSave.getText()。trim());

out = new BufferedOutputStream(new FileOutputStream(outFile) ));


long totalBytes = in.available();


jpb.setValue(0);

jpb.setMaximum(100);


int r;

long readBytes = 0;

byte [] b = new byte [10];

while((r = in.read(b,0,b.length))!= -1){

out.write(b ,0,r);

readBytes + = r;

currentValue =(int)(readBytes * 100 / totalBytes);


jpb.setValue(currentValue);

}

}


catch(FileNotFoundException ex){

ex.printStackTrace();

}


catch(IOException ex){

ex.printStackTrace();

}


最后{

尝试{

if(in!= null)in.close();

if(out!= null)out.close();

}

catch(Exception ex){}

}

}

i am working in copying file to other destination.my code doesnt work as expected.can anybody help me.i got this error message --->
java.io.FileNotFoundException: C:\Documents and Settings\XXXXXXX\My Documents (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.j ava:179)
at java.io.FileOutputStream.<init>(FileOutputStream.j ava:131)
at test1.PilihFail$Salin2.run(PilihFail.java:111)

the code is:
private int currentValue;

public void run(){

BufferedInputStream in = null;
BufferedOutputStream out = null;

try{
File inFile = new File(jtfOpen.getText().trim());
in = new BufferedInputStream(new FileInputStream(inFile));

File outFile = new File(jtfSave.getText().trim());
out = new BufferedOutputStream(new FileOutputStream(outFile));

long totalBytes = in.available();

jpb.setValue(0);
jpb.setMaximum(100);

int r;
long readBytes=0;
byte[] b = new byte[10];
while((r = in.read(b,0,b.length)) != -1){
out.write(b,0,r);
readBytes += r;
currentValue = (int)(readBytes * 100 / totalBytes);

jpb.setValue(currentValue);
}
}

catch(FileNotFoundException ex){
ex.printStackTrace();
}

catch(IOException ex){
ex.printStackTrace();
}

finally{
try{
if (in != null) in.close();
if (out != null) out.close();
}
catch(Exception ex){}
}
}

推荐答案

Salin2.run(PilihFail.java:111)


代码是:

private int currentValue;


public void run(){


BufferedInputStream in = null;

BufferedOutputStream out = null;


try {

File inFile = new File(jtfOpen.getText()。trim());

in = new BufferedInputStream(new FileInputStream(inFile));


文件outFile = new File(jtfSave.getText()。trim());

out = new BufferedOutputStream(new FileOutputStream(outFile));


long totalBytes = in.available();


jpb.setValue(0);

jpb.setMaximum(100);


int r;

long readBytes = 0;

byte [] b = new byte [10];

while(( r = in.read(b,0,b.length))!= -1){

out.write(b,0,r);

readBytes + = r;

currentValue =(int)(readBytes * 100 / totalBytes);


jpb.setValue(currentValue);

}

}


catch(FileNotFoundException ex){

ex.printStackTrace();

}


catch(IOException ex){

ex.printStackTrace();

}


最后{

尝试{

if(in!= null)in.close();

if(out!= null)out.close();

}

catch(Exception ex){}

}

}
Salin2.run(PilihFail.java:111)

the code is:
private int currentValue;

public void run(){

BufferedInputStream in = null;
BufferedOutputStream out = null;

try{
File inFile = new File(jtfOpen.getText().trim());
in = new BufferedInputStream(new FileInputStream(inFile));

File outFile = new File(jtfSave.getText().trim());
out = new BufferedOutputStream(new FileOutputStream(outFile));

long totalBytes = in.available();

jpb.setValue(0);
jpb.setMaximum(100);

int r;
long readBytes=0;
byte[] b = new byte[10];
while((r = in.read(b,0,b.length)) != -1){
out.write(b,0,r);
readBytes += r;
currentValue = (int)(readBytes * 100 / totalBytes);

jpb.setValue(currentValue);
}
}

catch(FileNotFoundException ex){
ex.printStackTrace();
}

catch(IOException ex){
ex.printStackTrace();
}

finally{
try{
if (in != null) in.close();
if (out != null) out.close();
}
catch(Exception ex){}
}
}



i我正在将文件复制到其他目的地。我的代码没有按预期工作。任何人帮助me.i收到此错误消息--->

java.io.FileNotFoundException:C:\Documents and Settings \XXXXXXX \ My Documents(访问被拒绝)

at java.io.FileOutputStream.open(Native Method)

at java.io.FileOutputStream。< init>(FileOutputStream.j ava:179)

在java.io.FileOutputStre am。< init>(FileOutputStream.j ava:131)

at test1.PilihFail
i am working in copying file to other destination.my code doesnt work as expected.can anybody help me.i got this error message --->
java.io.FileNotFoundException: C:\Documents and Settings\XXXXXXX\My Documents (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.j ava:179)
at java.io.FileOutputStream.<init>(FileOutputStream.j ava:131)
at test1.PilihFail


Salin2.run(PilihFail.java:111)

代码为:

private int currentValue;


public void run(){

BufferedInputStream in = null;

BufferedOutputStream out = null;


try {

File inFile = new file (jtfOpen.getText()。trim());

in = new BufferedInputStream(new FileInputStream(inFile));


File outFile = new File( jtfSave.getText()。trim());

out = new BufferedOutputStream(new FileOutputStream(outFile));


long totalBytes = in.available( );


jpb.setValue(0);

jpb.setMaximum(100);


int r ;

long readBytes = 0 ;

byte [] b =新字节[10];

while((r = in.read(b,0,b.length))!= -1 ){

out.write(b,0,r);

readBytes + = r;

currentValue =(int)(readBytes * 100 / totalBytes);


jpb.setValue(currentValue);

}

}


catch(FileNotFoundException ex){

ex.printStackTrace();

}


catch(IOException ex){

ex.printStackTrace();

}


最后{

尝试{

if(in!= null)in.close();

if(out!= null)out.close();

}

catch(Exception ex){}

}

}
Salin2.run(PilihFail.java:111)

the code is:
private int currentValue;

public void run(){

BufferedInputStream in = null;
BufferedOutputStream out = null;

try{
File inFile = new File(jtfOpen.getText().trim());
in = new BufferedInputStream(new FileInputStream(inFile));

File outFile = new File(jtfSave.getText().trim());
out = new BufferedOutputStream(new FileOutputStream(outFile));

long totalBytes = in.available();

jpb.setValue(0);
jpb.setMaximum(100);

int r;
long readBytes=0;
byte[] b = new byte[10];
while((r = in.read(b,0,b.length)) != -1){
out.write(b,0,r);
readBytes += r;
currentValue = (int)(readBytes * 100 / totalBytes);

jpb.setValue(currentValue);
}
}

catch(FileNotFoundException ex){
ex.printStackTrace();
}

catch(IOException ex){
ex.printStackTrace();
}

finally{
try{
if (in != null) in.close();
if (out != null) out.close();
}
catch(Exception ex){}
}
}



1.)发布代码时请使用代码标签。

2.)访问被拒绝是一个安全问题。您是否拥有试图访问的文件的权限?

1.) Please use code tags when posting code.
2.) Access denied is a security issue. Do you have rights to the file you are trying to access?


这篇关于问题复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆