Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help Reading from a file..
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JR




PostPosted: Sun Jun 06, 2004 4:35 pm   Post subject: Help Reading from a file..

Hey, my program opens the file and reads one line from it. how do i do it so it will read one line erase it then read the other line ect ect.?

code:

import java.awt.*;
import hsa.Console;
import java.io.*;
public class FinalProject
{
    static Console c;



    //Delay

    public static void delay ()
    {
        for (int counter = 1 ; counter < 20000 ; counter++)
        {
            double a = Math.PI * Math.PI;
        }
    }


    //End delay
    //Open question files from lvl 1
    public static void lvl1 () throws IOException
    {
        String line, answer;

        for (;;)
        {
            BufferedReader input;
            input = new BufferedReader (new FileReader ("lvl1.txt"));
            line = input.readLine ();


            c.drawString (line, 40, 80);
       
       
       
  }
  }
 


    public static void menu ()
    {
        c.setColor (Color.gray);
        c.fillRect (0, 0, 15, 550);
        c.fillRect (15, 410, 630, 25);
        c.fillRect (625, 0, 15, 550);
        c.fillRect (15, 0, 630, 15);
        c.fillRect (15, 250, 450, 15);
        c.fillRect (450, 0, 15, 550);
        c.fillRect (232, 250, 15, 500);
        c.fillRect (0, 332, 450, 15);
        c.setColor (Color.black);
        c.drawString ("$100", 520, 340);
        c.drawString ("$200", 520, 320);
        c.drawString ("$300", 520, 300);
        c.drawString ("$500", 520, 280);
        c.drawString ("$1000", 520, 260);
        c.drawString ("$2000", 520, 240);
        c.drawString ("$4000", 520, 220);
        c.drawString ("$8000", 520, 200);
        c.drawString ("$16000", 520, 180);
        c.drawString ("$32000", 520, 160);
        c.drawString ("$64000", 520, 140);
        c.drawString ("$125000", 520, 120);
        c.drawString ("$250000", 520, 100);
        c.drawString ("$500000", 520, 80);
        c.drawString ("$1000000", 520, 60);
    }


    public static void main (String [] args) throws IOException
    {
        c = new Console ();

        //open ();
        //Title
        c.println ("              *******************************************************");
        c.println ("              ******************** Welcome to************************");
        c.println ("              ***************Who wants to be a Millioner*************");
        c.println ("              *******************************************************");
        c.println ("              *******************************************************");
        //Getting ready to move to a new menu.
        c.println ("Press any key to continue");
        char chara;
        chara = c.getChar ();
        c.clear ();
        c.println ("1) Start Game");
        c.println ("2) Rules");
        c.println ("3) Top scores");
        c.println ("4) Exit");
        int num;
        num = c.readInt ();
        if (num == 1)
        {
            c.clear ();
            lvl1 ();




        }
        else if (num == 2)
        {
            String line1;
            BufferedReader input;
            input = new BufferedReader (new FileReader ("rules.txt"));
            line1 = input.readLine ();
            c.println (line1);
        }

        else if (num == 3)
        {
            String line2;
            BufferedReader input;
            input = new BufferedReader (new FileReader ("topscores.txt"));
            line2 = input.readLine ();
            c.println (line2);
        }

        else if (num == 4)
        {
            c.println ("Thank you for playing, bye");
        }


    } // main method
} // FinalProject class
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Tue Jun 08, 2004 11:10 pm   Post subject: (No subject)

If you whont to do that why not just read all the lines then delete the file or write over it with nothing affter u read all the lines?

To write to it you are going to need an output stream, there are seavaerl ways to do this and since you are using Ready to Progame all of them may not work.

The way i ushely do file out is with a PrintWriter witch you decaler like this:

PrintWriter fileOut = new PrintWriter(new FileWriter("myfilename.txt"));

and you can send out put to it like u do with the screen like this:

fileOut.println("LA LA");

or

fileOut.print("HA HA");
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: