blossompark
asked on
copying fles in java
Hi,
the code below takes a file (C:\\ANT\\Source\\Waterfal l.jpg) and creates a byte file of it and stores it at c:\\ANT\\Destination\\file 1.
Right now, the source file (Waterfall.jpg) must exist at c:\ANT\Source, also file1 need not exist at c:\ANT\Destination but it has to be in the argument of FileOutputStream or else I get a runtime error ;
Exception in thread "main" java.io.FileNotFoundExcept ion: c:\ANT\Destination (Access is denied)
at java.io.FileOutputStream.o pen(Native Method)
at java.io.FileOutputStream.< init>(File OutputStre am.java:17 9)
at java.io.FileOutputStream.< init>(File OutputStre am.java:70 )
at CopyBytes.main(CopyBytes.j ava:17)
////////////////////////// //////////
what i am trying to do is write an application that takes whatever is stored at c:\ANT\source converts it/them to corresponding byte files and store the byte files at c:\ANT\Destination.
any help appreciated.
thanks
the code below takes a file (C:\\ANT\\Source\\Waterfal
Right now, the source file (Waterfall.jpg) must exist at c:\ANT\Source, also file1 need not exist at c:\ANT\Destination but it has to be in the argument of FileOutputStream or else I get a runtime error ;
Exception in thread "main" java.io.FileNotFoundExcept
at java.io.FileOutputStream.o
at java.io.FileOutputStream.<
at java.io.FileOutputStream.<
at CopyBytes.main(CopyBytes.j
//////////////////////////
what i am trying to do is write an application that takes whatever is stored at c:\ANT\source converts it/them to corresponding byte files and store the byte files at c:\ANT\Destination.
any help appreciated.
thanks
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyBytes {
public static void main(String[] args) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("C:\\ANT\\Source\\Waterfall.jpg");
out = new FileOutputStream("c:\\ANT\\Destination\\file1");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
What's wrong so? Source should exists, cause you want to open it and read it, destination should not exists because you want to write there. Which part is problem and what you want to fix?
ASKER
I do not want to specify the file names in either source or destination.
When the program runs i want it to automatically look in C:\\ANT\\Source and convert any files it finds there into bytecode files.
I then want these bytecode files to be written to the c:\\ANT\\Destination folder...
When the program runs i want it to automatically look in C:\\ANT\\Source and convert any files it finds there into bytecode files.
I then want these bytecode files to be written to the c:\\ANT\\Destination folder...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi CSecurity,
thanks thats great...works a treat... been googling this all day and no joy!!
thanks again
thanks thats great...works a treat... been googling this all day and no joy!!
thanks again