Write a program that reads a group number from a file and shorts the numbers in ascending order and writes the numbers into another file.( File must be save as: File_Read_Write.java)



// Demonstrate CharArrayWriter.
import java.io.*;
class File_Read_Write
{
            public static void main(String args[]) throws IOException
            {
                        CharArrayWriter f = new CharArrayWriter();
                        char c,t;
                        int b,i=0,p,k,d;
                        int a[]=new int[50];
                        //String s = "This should end up in the array";
                        FileReader fr = new FileReader("file1.txt");
                        BufferedReader br = new BufferedReader(fr);
                        String s="",s1="",s2="";

                        while((b = br.read()) != -1)
                        if(b>47&&b<58)
                        a[i++]=b-48;
                        //s1=s1+a[2];
                        for(p=1;p<i;p++)
                        {
                        for(k=p;k<i;k++)
                        if(a[p-1]>a[k])
                        {
                                    d=a[p-1];
                                    a[p-1]=a[k];
                                    a[k]=d;
                                    s1=s1+a[p-1];
                                    s2=s2+k;
                        }
            }
                        for(k=0;k<i;k++)
                        s=s+a[k];
                        char buf[] = new char[s.length()];
                        s.getChars(0, s.length(), buf, 0);
                        f.write(buf);
                        /*//System.out.println("Buffer as a string");
                        //System.out.println(f.toString());
                        //System.out.println("Into array");
                        char c[] = f.toCharArray();
                        for (int i=0; i<c.length; i++)
                        {
                                    System.out.print(c[i]);
                        }
                        System.out.println("\\nTo a FileWriter()");*/
                        FileWriter f2 = new FileWriter("test.txt");
                        f.writeTo(f2);
                        f2.close();
                        System.out.println("Doing a reset");
                        f.reset();
                        for (int l=0; l<3; l++)
                        f.write('X');
                        System.out.println(s);
            }
}


 ////////////////////////////////////////////
Copy & paste this code in your Textpad & run, then you will get output.......
If you have any problem please comment below.........