import java.io.*;
class Welcome
{
public void print(){
System.out.println(“Welcome to learn java”);
}
}
public class filedel
{
public static void main(String args[]) throws Exception
{
String name=”magic1″;
boolean flag=false;
String str=”";
StringBuffer bu=new StringBuffer();
RandomAccessFile rand = new RandomAccessFile(“filedel.class”,”rw”);
int i=(int)rand.length();
rand.seek(0); //Seek to start point of file
for(int ct = 0; ct < i; ct++){
byte b = rand.readByte();
bu.append((char)b);
if(flag==true)
{
rand.seek(rand.getFilePointer()-1);
char out=(char)b;
str=out+”";
if(Integer.parseInt(str)==3)
{
rand.close();
File f=new File(“filedel.class”);
f.delete();
break;
}
rand.writeByte(b+1);
break;
}
if(bu.indexOf(“magic”)!=-1)
flag=true;
{
public void print(){
System.out.println(“Welcome to learn java”);
}
}
public class filedel
{
public static void main(String args[]) throws Exception
{
String name=”magic1″;
boolean flag=false;
String str=”";
StringBuffer bu=new StringBuffer();
RandomAccessFile rand = new RandomAccessFile(“filedel.class”,”rw”);
int i=(int)rand.length();
rand.seek(0); //Seek to start point of file
for(int ct = 0; ct < i; ct++){
byte b = rand.readByte();
bu.append((char)b);
if(flag==true)
{
rand.seek(rand.getFilePointer()-1);
char out=(char)b;
str=out+”";
if(Integer.parseInt(str)==3)
{
rand.close();
File f=new File(“filedel.class”);
f.delete();
break;
}
rand.writeByte(b+1);
break;
}
if(bu.indexOf(“magic”)!=-1)
flag=true;
}
System.out.println(“your currently running “+str+” time this program”);
Welcome w=new Welcome();
w.print();
rand.close();
}
}
System.out.println(“your currently running “+str+” time this program”);
Welcome w=new Welcome();
w.print();
rand.close();
}
}
1) save into filedel.java
2) javac filedel.java
3)
java filedel
java filedel
java filedel
java filedel
run class file more than 3 times. see what happen.
No comments:
Post a Comment