Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Writing to a file



Thought this would be simple now that I can use Java 1.3

here's the code that I am using to create a file and write some stuff to
it. "docHeader" and the rest are defined elsewhere as Strings and I'll
remove the quotes - right now I'd be happy to write ANYTHING to the file.

TIA,
Jon

------------------
import java.io.*;

public class testClass {
public static void main(String[] args) {

if (args.length == 1) {
File fileOut = new File("/space/users/swd/java/"+args[0]);
FileWriter fw = null;
try {
boolean fileWasMade = fileOut.createNewFile();
if (fileWasMade == true) {
System.out.println("\n\nsaving file at: "+fileOut+"\n");
fw = new FileWriter(fileOut);
fw.write("docHeader");
fw.write("pageLayoutHTML");
fw.write("docFooter");
}
else {
System.out.println("File exists - try again\n");
}
}
catch (IOException ioe) {
System.out.println("oops");
}
}
else {
System.out.println("USAGE: java testClass filename\n");
}
}
}

-----------------------------------

----------------------------------------
I am therefore I think ... different
----------------------------------------
Jon Lucenius email@hidden
JCL Technologies email@hidden
Phone 302-369-2989
FAX 302-369-3016




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.