Results 1 to 3 of 3
  1. #1
    swati.jyoti is offline Member
    Join Date
    Mar 2009
    Posts
    42
    Rep Power
    0

    Default open a file using read or write mode

    How can i open a file in read or write mode using File but not random access file?

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    431
    Rep Power
    6

    Default

    You can create your file object in read or write mode .
    It should be done before creating streams
    Mak
    (Living @ Virtual World)

  3. #3
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    I am not the greatest with reading and writing to files, but basically you want to do something like:

    Java Code:
                File f = new File("myFile.txt");
    
                if (f.exists()) {
    
                try {
    
                    BufferedWriter out = new BufferedWriter(new FileWriter(f));
                    String str = "Write some Stuff...";
    
    
                    out.write(str);
                    out.flush();
                    out.close();
    
    
    
                } catch (FileNotFoundException fe) {
                } catch (IOException io) {
                }
    
                try {
    
                    BufferedReader in = new BufferedReader(new FileReader(f));
    
                    System.out.println(in.readLine());
    
                    in.close();
                
    
                } catch (FileNotFoundException fe) {
                } catch (IOException io) {
                }
    Who Cares... As Long As It Works...

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2009, 10:28 AM
  2. Open xls file in read-write mode
    By rdhaware in forum Advanced Java
    Replies: 1
    Last Post: 02-03-2009, 08:12 AM
  3. Replies: 5
    Last Post: 01-20-2009, 09:08 AM
  4. Read and Write file
    By mrdestroy in forum New To Java
    Replies: 13
    Last Post: 10-31-2008, 12:11 PM
  5. File read/write problems
    By p900128 in forum New To Java
    Replies: 4
    Last Post: 06-27-2008, 12:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •