This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
bananaman
Indestructible


Calc Guru


Joined: 12 Sep 2005
Posts: 1124

Posted: 11 Oct 2007 05:03:56 pm    Post subject:

I am attempting to write a program it Java, but I am running into difficulties. For some strange reason I cannot seem to read text from a file. Here is my code maybe someone else can see what I am doing wrong.


Code:
import java.util.*;
import java.io.*;

public class SetUp {
   public static void main(String[] args) throws FileNotFoundException {
  Scanner scan = new Scanner(new File("Questions"));
  Scanner keyboard = new Scanner(System.in);
  while (scan.hasNextLine()) {
     System.out.println(scan.nextLine());
     keyboard.nextLine();
  }
   }
}

I have a file called Questions that is located inside the same folder as the program. This is being done on a mac.
Edit:
I'm throwing in another stupid question as well.
Is there a way to make text inside a JButton See through?


Last edited by Guest on 11 Oct 2007 05:44:05 pm; edited 1 time in total
Back to top
spandiv
-- Retired --


Active Member


Joined: 25 May 2003
Posts: 650

Posted: 11 Oct 2007 05:54:14 pm    Post subject:

I just tried your sample program on my computer (I also created a dummy Questions.txt file to read from), and it didn't work. However, I got it to work by adding a .txt extension to "Questions". The one other thing I changed is I removed the second Scanner object, since you really only need one Scanner object for reading in a file.

Last edited by Guest on 11 Oct 2007 06:41:59 pm; edited 1 time in total
Back to top
bananaman
Indestructible


Calc Guru


Joined: 12 Sep 2005
Posts: 1124

Posted: 11 Oct 2007 06:04:46 pm    Post subject:

The 2nd object was for me to see the contents one at a time.
Back to top
bananaman
Indestructible


Calc Guru


Joined: 12 Sep 2005
Posts: 1124

Posted: 11 Oct 2007 10:38:50 pm    Post subject:

I figured out my second problem.

new Color(0, true)
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 12 Oct 2007 06:30:34 am    Post subject:


Code:
joe@NAVI ~/Desktop $ javac SetUp.java
joe@NAVI ~/Desktop $ echo "blah blah" >> "Questions"
joe@NAVI ~/Desktop $ cat Questions
blah blah
joe@NAVI ~/Desktop $ java SetUp
blah blah
joe@NAVI ~/Desktop $


Although it seems to hang at the end and I have to kill it, but it does read fine. Something is wrong with where you're putting the file or what you're calling it. I'd look at your code, but honestly I haven't used java in a few years, since it's absolutely worthless :P

But it seems to work for me.
Back to top
bananaman
Indestructible


Calc Guru


Joined: 12 Sep 2005
Posts: 1124

Posted: 12 Oct 2007 06:41:59 am    Post subject:

I believe that my problem was that I was using eclipse. When I manually went into the terminal it seemed to work just fine. Thank you for all your help. I'm sorry that my responses are short, but I'm still learning dvorak and it takes awhile to type anything.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement