Results 1 to 3 of 3

Thread: Open and write text file in JAVA

  1. #1
    Davismoore is offline Senior Member
    Join Date
    Dec 2009
    Posts
    284
    Rep Power
    3

    Default Open and write text file in JAVA

    I just started learning Java and I want to know how to open txt file and include text to it. So please provide me some suggestions about this. Any help will be appreciated.

  2. #2
    JacksonPerez is offline Banned
    Join Date
    Dec 2009
    Posts
    274
    Rep Power
    0

    Default

    Try the following code to solve your problem:

    Code:
    try {
         FileOutputStream flout = new FileOutputStream(directory / file.txt);
         flout.write(text.getBytes());
         flout.close();
    }
    catch(IOException ioe) {
         / / Handle exceptions related to file access
    }

  3. #3
    ThompsonHarris is offline Senior Member
    Join Date
    Dec 2009
    Posts
    255
    Rep Power
    3

    Default

    See the code given below which may help you:

    Code:
    import java.io.File;
    Public class mfl {
    Public mfl() {
    	great();
    	}
     	 Public String mthd(String path) throws Exception{	  
    	  File fl = new File(path);  
    	  if(fl.exists()& & File.canRead()){
    		  
    		  return "Ok"; / / message
    	  }
    	  else
    	  {
    		  return "Not Ok"; / / message
    	  }  } }

Similar Threads

  1. Replies: 1
    Last Post: 05-03-2010, 01:37 PM
  2. Opening and editing text file in java
    By WilsonMartin in forum Programming
    Replies: 2
    Last Post: 03-30-2010, 01:02 PM
  3. How to write a element Listener in Java?
    By Brownchris in forum Software Jargons
    Replies: 1
    Last Post: 02-13-2010, 01:56 PM
  4. write sequence data java program
    By Brownchris in forum Programming
    Replies: 1
    Last Post: 01-22-2010, 06:09 PM
  5. Write program on palindrome in java
    By MoralesMyers in forum Programming
    Replies: 2
    Last Post: 01-14-2010, 06:24 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48