Advertisement

File I/O In Java

Started by September 28, 2000 08:57 PM
0 comments, last by Cajun Coder 24 years, 3 months ago
I know this sounds odd, but I just can''t seem to make a file! I''ve tried the java.io.* package, resorted the the WFC and still nothing... Would anybody be able to show me how to make a file? Any file.. just create a file, print a number to it and then load it again and get that number... is it too much to ask from a language named after coffe? this is my current attempt using the WFC.. // I would like it in the // code base directory, but im willing to settle for now String loadFile = "c:\\saveGame\\";loadFile = loadFile + charName + ".dds" try { File file; file = File.create (saveFile); file.writeInt (x); file.close (); } catch (IOException ioe) { // nothing, just work! } is it even possible for java to create a file? Even with the WFC? I''m kinda dying here, anything would help. Thanks! -Cajun Christopher.Smith@Trinity.edu
Used BufferedWriter for output and BufferedReader for input.

Something like this:
    BufferedWriter out = new BufferedWriter( new FileWriter("file.name" ));out.write( number );out.flush();out.close();BufferedReader in = new BuffereeReader( new FileReader( "file.name" ));number = in.read();in.close();    

This topic is closed to new replies.

Advertisement