How to create file with text.




   

This   code  can be use   to   create  a  file   with desired  text .  you can  enter  desired file
name  and  text you want to write  in the file . 




import java.io.*; 
import java.lang.*;
class CreateandReadfile
{
  public static void main(String[] args) throws IOException {
               char c;
                  String fname = "";
               FileOutputStream fos=null; 
                System.out.println("enetr file name"); 
                BufferedReader br=new BufferedReader(new                                                        InputStreamReader(System.in));
                    
                           fname= br.readLine();
                 
                    try {
                        
                          fos=new FileOutputStream(fname); 
                                }
                             catch(FileNotFoundException e) {
                             System.out.println(e); }
                             System.out.println("enter any text matter");
                           do
                             {
                             c=(char)System.in.read();
                             fos.write(c);
                             
                             System.out.println(" type q to stop");
                          
                              }while(c!='q');
                          fos.close(); 
                         }
                       }




 If   run this code   like  this  i  created  a text file  . Output will a  file  with
 your text . Just like this .

      enetr file name
       iomayo
       enter any text matter

       this is iomayo  oaku khayo q




How to create file with text.  How to create file with text. Reviewed by Mukesh Jha on 4:18 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.