السلام عليكم ورحمة الله وبركاته
أرجو أن لا أكون قد أثقلت عليكم يا اخواني بالأسئلة؟ ... عندي سؤال قد حيرني قليلا وهو حول نسخ ملف من مجلد الى مجلد آخر
كتبت كود أو بالأحرى نقلت كود من أحد الدروس من الانترنت, والذي أجده هو رسالة خطأ تقول لي: Access Denied
أولا دعوني أعرض عليكم الكود ومن ثم أرجو من أخواني والذين استخدموا هذه التجربة (نسخ الملفات بجافا) أن لا يبخلوا علينا بالبيان
كود
import java.io.*;
public class Copy {
String from,to;
File file;
public Copy()
{
from = "c:/Earth.jpg";
to = "d:/Documents/copyfiles/";
try
{
file = new File(from);
}
catch(Exception e)
{
file = null;
e.printStackTrace();
System.out.println("Where is the file?");
}
if(file != null)
{
try
{
BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(from));
BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(to));
byte[] bytes=new byte[1024];
int count = 0;
while( (count=inStream.read(bytes))!=-1 ){
outStream.write(bytes,0,count);
}
outStream.close();
inStream.close();
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("File transferred: ");
}
else
{
System.out.println("no such url");
}
}
public static void main(String[] args) throws IOException {
new Copy();
}
}
public class Copy {
String from,to;
File file;
public Copy()
{
from = "c:/Earth.jpg";
to = "d:/Documents/copyfiles/";
try
{
file = new File(from);
}
catch(Exception e)
{
file = null;
e.printStackTrace();
System.out.println("Where is the file?");
}
if(file != null)
{
try
{
BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(from));
BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(to));
byte[] bytes=new byte[1024];
int count = 0;
while( (count=inStream.read(bytes))!=-1 ){
outStream.write(bytes,0,count);
}
outStream.close();
inStream.close();
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("File transferred: ");
}
else
{
System.out.println("no such url");
}
}
public static void main(String[] args) throws IOException {
new Copy();
}
}