Reading input and writing output

From: slickn_sly (bng_s_at_hotmail-dot-com.no-spam.invalid)
Date: 01/30/05

  • Next message: Casey Hawthorne: "Re: How do I determine how many times an application has started?"
    Date: 30 Jan 2005 16:33:55 -0600
    
    

    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
    *---------------------------------*


  • Next message: Casey Hawthorne: "Re: How do I determine how many times an application has started?"

    Relevant Pages

    • Re: Java meets UNIX
      ... >> java.io.File#mkdirsist dein Freund, ebenso BufferedReader, ... * Executes the given String as Command on the command line using ... String lastLine = null; ...
      (de.comp.lang.java)
    • Newbie server response question
      ... I am trying to build a very simple server. ... I am having trouble with the listening part. ... the following code listening for the command (the string variable ... BufferedReader in = new BufferedReader( ...
      (comp.lang.java.programmer)
    • Streams
      ... Can i use the following constructions in a server and client without being ... BufferedReader in = new BufferedReader( ... PrintWriter pout = new PrintWriter ...
      (comp.lang.java.help)
    • Re: Extracting strings from text files
      ... In my application I have a file which acts as a lookup table with two ... BufferedReader br = new BufferedReader ); ... String deviceName = line.substring ... List rows = new ArrayList; ...
      (comp.lang.java.programmer)
    • String intelligent in Datei suchen =?ISO-8859-15?Q?=28Rechtschre?= =?ISO-8859-15?Q?i
      ... Nun muss ich nur noch eine Sprachliste einbinden, damit nicht alles farbig angezeigt wird :-) Zwei Beispiele habe ich zum Suchen eines String in einer Textdatei gefunden. ... BufferedReader br = new BufferedReader( ... So wird zuerst im Cache gesucht, dann in der Datei. ...
      (de.comp.lang.java)