PROGRAM
import java.io.*;
class files
{
String s[]=new String[100];
String str="",m,t;
int x,size=0,i,tem,j=0,chg;
int a[]=new int[100];
int b[]=new int[100];
int c[]=new int[100];
files(String s1,String s2)throws IOException
{
File r=new File(s1);
File w=new File(s2);
FileInputStream fin=new FileInputStream(r);
FileOutputStream fout=new FileOutputStream(w);
do{
i=fin.read();
if(i!=-1)
{
str=str+(char)i;
if((char)i=='\n')
{
s[j]=str;
j++;
size++;
str="";
}
}
}
while(i!=-1);
for(int l=0;l
{
if(s[l]==null)
break;
m=s[l];
t="tata";
b[l]=a[l]=search(m,t);
}
for(int p=0;p
{
for(int q=0;q
{
if(b[q]
{
tem=b[q];
b[q]=b[q+1];
b[q+1]=tem;
}
}
}
for(int h=0;h
{
x=b[h];
c[h]=linear(x,a,size);
}
for(int y=0;y
{
chg=c[y];
byte buf[]=s[chg].getBytes();
fout.write(buf);
}
}
static int linear(int x,int a[],int size)
{
int m,d,item=x,siz=size;
for(d=0;d<=siz;d++)
{
if(item==a[d])
{
m=d;
break;
}
}
return d;
}
static int search(String m,String c)
{
int ch,ma,inc=0;
String pat,main,check;
pat=main=m;
check=c;
do{
pat=main.substring(0,4);
if(pat.equalsIgnoreCase(check))
++inc;
main=main.substring(1);
ch=check.length();
ma=main.length();
}
while(ch
return inc;
}
}
class filehand
{
public static void main(String a[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
String s1,s2;
System.out.println("enter the read file name :");
s1=in.readLine();
System.out.println("enter the write file name:");
s2=in.readLine();
files f=new files(s1,s2);
System.out.println("successfully writed");
}
}
OUTPUT:
C:\j2sdk1.4.0\bin>javac filehand.java
C:\j2sdk1.4.0\bin>java filehand
enter the read file name :
input.txt
enter the write file name:
output.txt
successfully writed
“Input.txt”
jfjksdf tata fji
fjksdfi tatt fg tata taata tata
jfijsdf tata tjkltj tatta tata tata
“Output.txt”
jfijsdf tata tjkltj tatta tata tata
fjksdfi tatt fg tata taata tata
jfjksdf tata fji
1 comment:
Thanks a ton for the codes. I also found some free GATE tests.http://thegateacademy.com/gate-free-test/
Post a Comment