OSA B11



B11:Java Working with startup scripts. (Init script)



program:

import java.io.*;
class assign11
{
 public static void main(String[] args) throws FileNotFoundException,UnsupportedEncodingException
 {
System.out.println("\n Your script has been sucesfully initialized. Reboot your system.");
  File file = new File("/home/joker415/temp/");        
  String[] myFiles;
  int count=0;     
  if(file.isDirectory())
  {  
   myFiles = file.list();  
   for (int i=0; i<myFiles.length; i++)
   {  
    File myFile = new File(file, myFiles[i]);   
    if(myFile.delete())
    {
     count++;
    }
   }  
  }  
  System.out.println("\n"+count+" Files and Directory are deleted successfully..");
  PrintWriter writer =new PrintWriter("/home/joker415/init_scripts/log.txt","UTF-8");
  writer.println("\n ----------------------------------------------------");
  writer.println("\n"+count+"  Files are deleted successfully");
  writer.println("\n --------------------x-o-x---------------------------\n");
  writer.close();
PrintWriter writer1 =new PrintWriter("/etc/rc.d/rc.local","UTF-8");
  writer1.println("#!/bin/bash");
  writer1.println("cd /home/joker415/init_scripts/");
  writer1.println("java assign11");
  writer1.close();


 }

}

0 comments:

Post a Comment