Sunday, June 19, 2016

File Programs

import java.io.*;
import java.util.*;
class FileDemo
{
   public static void main(String arg[])
    {
     File f=new File("xyz.txt");
     System.out.println("File object= "+f);
     System.out.println("File path= "+f.getPath());
     System.out.println("File Absolute path= "+f.getAbsolutePath());
     System.out.println("Contents= "+f.length());
     System.out.println(f.exists() ? "File is in existence": "File not in existence");
     System.out.println(f.canRead() ? "File is readable": "File not readable");
     System.out.println(f.canWrite() ? "File is in writable": "File not writable");
     System.out.println("Parent= "+f.getParent());
     System.out.println("Name= "+f.getName());
     System.out.println("Flie Modi at="+ new Date(f.lastModified()));
    }
   }import java.io.*;
import java.util.*;
class FileDemo1
{
   public static void main(String arg[])
    {
     File f1=new File("c:/ashish/xxx");
     File f2=new File("c:/ram/siva/jj");
     if(f1.mkdirs())
      {
  System.out.println("Path found and Dir Created");
 }
 else
  {
     System.out.println("Dir Exist");
}
 if(f2.mkdirs())
  {
     System.out.println("Nested Dir are Created");
}
else
{
  System.out.println("Nested Dir Exists");
 }

}
}import java.io.*;
import java.util.*;
class FileListDemo
{
  public static void main(String arg[])
{
String path="F:\studies\java\java. program\All java Programs\ashish\";
File f1=new File(path);
String []flist=f1.list();
for(int i=0;i   {
File f2=new File(path,flist[i]);
if(f2.isFile())
 {
  System.out.println(flist[i]+"is File");
 }
else if(f2.isDirectory())
 {
 System.out.println(flist[i]+"is Dir");
 }
  }
}
}
import java.io.*;
class Fisdemo
{
 public static void main(String args[])
 {
   try
   {
   FileInputStream fis= new FileInputStream("Fisdemo.java ");
   int d=0;
   while((d=fis.read())!=-1)
   {
     System.out.print((char)d);
   }
   fis.close();
   System.out.println("Reading is over");
 }
 catch(IOException ie)
 {
   System.out.println("Error is" +ie);
  }
 }
 }  import java.io.*;
  class FISDemo
  {
  public static void main(String s[])
  {
  try
  {
BufferedReader br=neew BufferedReader(new InputStreamReader(S
  FileInputStream fis=new FileInputStream("FISDemo.java");
  int i=0;
  while((i=fis.read())!=-1)
  {
  System.out.print((char)i);
  }
  fis.close();
  System.out.println("\nReading is over");
  }
  catch(IOException e)
  {
  System.out.println("Error is"+e);
  }
  }
  }
  import java.io.*;
  class FISDemo
  {
  public static void main(String s[])
  {
  try
  {
  FileInputStream fis=new FileInputStream("FISDemo.java");
  int i=0;
  while((i=fis.read())!=-1)
  {
  System.out.print((char)i);
  }
  fis.close();
  System.out.println("\nReading is over");
  }
  catch(IOException e)
  {
  System.out.println("Error is"+e);
  }
  }
  }
import java.io.*;
class Fosdemo
{
 public static void main(String args[])
 {
   try
   {char ch='y';
   while(ch=='y' || ch=='Y')
    {
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

   FileOutputStream fos= new FileOutputStream("c:/ashish/Fileoutdemo.java ",true);
   System.out.println("Enter data to be written");
   String data=br.readLine();
   data=data.concat("\n");
   byte bytedata[]=data.getBytes();
   System.out.println("Writing on file");
   fos.write(bytedata);
   System.out.println("Writing is over");
   System.out.println("Do you want to cont");
    ch=(char)br.read();

   fos.close();
}
 }

 catch(IOException ie)
 {
   System.out.println("Error is" +ie);
  }
 }
 }  import java.io.*;
  class FOSDemo1
  {
  public static void main(String s[])
  {
  try
  {char ch='y';
  while(ch=='y'|| ch=='Y')
  {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  FileOutputStream fos=new FileOutputStream("d:/Rahul/xxx/rade.txt");

  System.out.println("Enter data to be write");
  String str=br.readLine();
     byte data[]=str.getBytes();
  System.out.println("Writes data in a file");
  fos.write(data);
  System.out.println("Writin is over\n");
  fos.close();
  System.out.println("Do u want to continue(y/n)");
  ch=(char)br.read();
}
  }
  catch(IOException e)
  {
  System.out.println("Error is"+e);
  }
  }
  }
import java.io.*;
class FPwsdemo
{
 public static void main(String args[])
 {try{
FileWriter fw=new FileWriter("aaa.txt",true);
  PrintWriter p=new PrintWriter(fw);
  p.println("Hello!");
  p.flush();
 }catch(Exception e)
   {
   System.out.println("Error is"+e);
}
}

 }  import java.io.*;
  class FRDemo
  {
  public static void main(String s[])
  {
  try
  {
FileReader fr=new FileReader("d:/curser.txt");
  BufferedReader br=new BufferedReader(fr);
  String data="";
while((data=br.readLine())!=null)
{
System.out.println(data);
}
  fr.close();
  System.out.println("Reading is over");
}
  catch(IOException e)
  {
  System.out.println("Error is"+e);
  }
  }
  }
import java.io.*;
class Frsdemo
{
 public static void main(String args[])
 {
   try
   {
   FileReader frs= new FileReader("Frsdemo.java ");
   BufferedReader br=new BufferedReader(frs);
   String str="";
   while((str=br.readLine())!=null)
   {
     System.out.println(str);
   }
   frs.close();
   System.out.println("Reading is over");
 }
 catch(IOException ie)
 {
   System.out.println("Error is" +ie);
  }
 }
 }  import java.io.*;
  class FWDemo
  {
  public static void main(String s[])
  {
  try
  {
char ch='y';
while(ch=='y'|| ch=='Y')
{
FileWriter fw=new FileWriter("d:/Rahul/priyam.txt",true);
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter data to be write");
  String data=br.readLine();
fw.write(data);
System.out.println("Writing is over \nDo u want to continue");
ch=(char)br.read();
fw.close();
}
}

  catch(IOException e)
  {
  System.out.println("Error is"+e);
  }
  }
  }
import java.io.*;
class Fwsdemo
{
 public static void main(String args[])
 {
   try
   {
   FileWriter fws= new FileWriter("aaa.txt ",true);
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   String str=br.readLine();
   fws.write(str+"\n");
   fws.close();
   System.out.println("Writing is over");
 }
 catch(IOException ie)
 {
   System.out.println("Error is" +ie);
  }
 }
 }import java.io.*;
class PrintWriterDemo1
{
public static void main(String s[])
{
try
{
FileWriter fw=new FileWriter("d:/Rahul/priyam.txt",true);
PrintWriter pw=new PrintWriter(fw);
pw.println("Hello");
pw.println("Deepak");
System.out.println("Writing is over");
pw.flush();
}
catch(Exception e)
{
}
}
}

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...