For some reason, I'm getting an error. It doesn't seem to be reading
my "input.txt" file. I'm trying to read the "input.txt" file which
consits of random integers and use insertion sort to sort them in
order. Then, i want to have the sorted integers go the file
"output.txt"
static final int MAX_NUM = 100;
public static void main( String[] args ) throws java.io.IOException
{
int[] num = new int[MAX_NUM];
FileReader fr = new FileReader("input.txt");
BufferedReader br = new BufferedReader( fr );
PrintWriter out = new PrintWriter( new BufferedWriter( new FileWriter(
"output.txt" ) ) );
int count = 0;
while ( count < MAX_NUM )
{
String line = br.readLine();
if( (line == null) || line.equals( "" ) )
break;
try
{
num[count] = Integer.parseInt( line );
count++;
}
catch( Exception e)
{
System.out.println( "ERROR" );
}
//System.out.println( line );
//line = br.readLine();
}
insertionSort( num );
for( int i = 0; i < count; i++ )
{
out.println( Integer.toString( num ) );
}
out.close();
}
*---------------------------------*
Posted at: http://www.GroupSrv.com
Check: http://www.HotCodecs.com
*---------------------------------*