I have a text file containing 10 rows. Each row has 10 elements separated by commas which are already sorted row wise like:
3463,34957,44443,50481,71036,73503,74289,76671,82462,92527
1456,2731,18159,20440,32962,38562,49321,64220,67615,72541
1073,6217,9695,27372,30624,38021,47851,68479,76834,88021
7930,11882,17681,27267,32131,45096,59008,69156,72843,94146
2381,4359,30194,40730,73714,74721,75127,78830,86753,89475
1466,21335,21369,23342,36973,50888,67891,78069,90346,99970
15015,16628,21012,25483,42387,42519,45472,49552,57193,71449
1751,8833,35433,39972,44475,47604,51601,59108,87957,94764
10728,17248,31885,41453,41479,54785,81400,83554,86014,87105
228,9479,25187,50956,70720,71878,78744,84341,86637,88225
Now i want to sort these 100 elements without disturbing the row order (i.e: The smallest number (228) should be at first position and largest number (99970) should be at the last position and i need to store those fully Sorted numbers into another file.
I am facing problem to add these numbers in Array and then i want to know how to sort these. The constraint is not more than 10 elements should be in RAM at a time.
I have started to written some code for this purpose to get data from the file:
public static void main(String args[])
{
File file = new File("SortedLines.txt");
FileInputStream fis = null;
String st;
try
{
fis = new FileInputStream(file);
int content;
while ((content = fis.read()) != -1)
{
// convert to char and display it
System.out.print((char)content);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}