Thread: Java I/o Help
View Single Post
Old Nov 2nd, 2004, 10:21 AM   #2
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
Reading a file's contents: (from http://javaalmanac.com/egs/java.io/R...sFromFile.html)
 * *try {
 * * * *BufferedReader in = new BufferedReader(new FileReader("infilename"));
 * * * *String str;
 * * * *while ((str = in.readLine()) != null) {
 * * * * * *process(str);
 * * * *}
 * * * *in.close();
 * *} catch (IOException e) {
 * *}

Read from one file and write to another: (from http://javaalmanac.com/egs/java.io/CopyFile.html?l=new)
 * *// Copies src file to dst file.
 * *// If the dst file does not exist, it is created
 * *void copy(File src, File dst) throws IOException {
 * * * *InputStream in = new FileInputStream(src);
 * * * *OutputStream out = new FileOutputStream(dst);
 * *
 * * * *// Transfer bytes from in to out
 * * * *byte[] buf = new byte[1024];
 * * * *int len;
 * * * *while ((len = in.read(buf)) > 0) {
 * * * * * *out.write(buf, 0, len);
 * * * *}
 * * * *in.close();
 * * * *out.close();
 * *}

hope that will help get your started. Note the classes used to read and write. You can find them in the JavaTM 2 Platform, Standard Edition, v 1.4.2 API Specification under java.io
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote