473,416 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

how can i incorporate my reader file to my program

My program works reading from values that I have stored in an array for valid account numbers. I also have a file that reads the valid account numbers from a text file. I need to read from the text file and not the array.

reads from array
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner; 
  2.  
  3.    public class ChargeAccount 
  4.    { 
  5.       static int[] validChargeAccountNumbers = 
  6.       { 
  7.          5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 8080152, 
  8.          4562555, 5552012, 5050552, 7825877, 1250255, 1005231, 6545231, 
  9.          3852085, 7576651, 7881200, 4581002 
  10.          }; 
  11.  
  12.       public static void main(String[] args) 
  13.       { 
  14.          Scanner in = new Scanner(System.in); 
  15.  
  16.       // Ask the user for an account number 
  17.          System.out.print("Please enter an account number: "); 
  18.  
  19.       // Get the number from the user 
  20.          int number = in.nextInt(); 
  21.  
  22.       // Check to see if the number is valid 
  23.          if (ChargeAccount.isValid(number) == true) 
  24.          { 
  25.             System.out.println("That account number is valid."); 
  26.          } 
  27.  
  28.          else 
  29.          { 
  30.             System.out.println("You did not enter a valid account number."); 
  31.          } 
  32.       } 
  33.  
  34.        // Check to see if an account number is valid by comparing it to the entries in the array of valid numbers 
  35.       public static boolean isValid(int number)       
  36.       { 
  37.  
  38.       // Perform sequential search through list of valid account numbers 
  39.          for (int i = 0; i < validChargeAccountNumbers.length; i++) 
  40.          { 
  41.  
  42.       // Check to see if the number we were given is at the ith position in the list 
  43.          if (validChargeAccountNumbers[i] == number) 
  44.          { 
  45.             return true; 
  46.          } 
  47.       } 
  48.  
  49.       // If we get down here, then we never found it in the list 
  50.              return false; 
  51.       } 
  52.    }
  53.  
file reader
Expand|Select|Wrap|Line Numbers
  1. mport java.io.*;
  2.  
  3.  
  4.    class FileReadTest 
  5.    {
  6.       public static void main (String[] args) 
  7.       {
  8.          FileReadTest f = new FileReadTest();
  9.          f.readMyFile();
  10.       }
  11.  
  12.       void readMyFile() 
  13.       {
  14.          DataInputStream dis = null;
  15.          String record = null;
  16.          int recCount = 0;
  17.  
  18.          try 
  19.          {
  20.             File f = new File("valid_accounts.txt");
  21.             FileInputStream fis = new FileInputStream(f);
  22.             BufferedInputStream bis = new BufferedInputStream(fis);
  23.             dis = new DataInputStream(bis);
  24.  
  25.             while ( (record=dis.readLine()) != null ) 
  26.             {
  27.                recCount++;
  28.                System.out.println(recCount + ": " + record);
  29.             }
  30.          } 
  31.  
  32.             // catch io errors from FileInputStream or readLine()
  33.             catch (IOException e) 
  34.             {
  35.                System.out.println("Uh oh, got an IOException error!" + e.getMessage());
  36.             } 
  37.  
  38.          finally 
  39.          {
  40.  
  41.           // if the file opened okay, make sure we close it
  42.             if (dis != null) 
  43.             {
  44.                try 
  45.                {
  46.                   dis.close();
  47.                } 
  48.                   catch (IOException ioe) 
  49.                   {
  50.                   }
  51.             }
  52.          }
  53.       }
  54.    }
  55.  
Sep 13 '10 #1

✓ answered by Oralloy

Ouch. Then you are one frustrated kid.

Still, your code looks good. All you need is the read-file bit and you're done.

Did you ever bother to read that link I sent?

This is a simplified bit of code that might work for you, but it'll never fly in a production environment where people seem to put all kinds of junk in files. The problem is, of course, in error detection and reporting:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.   Scanner s = new Scanner(new File(fileName));
  3.  
  4.   while(s.hasNextInt())
  5.     validChargeAccountNumbers.add(s.nextInt());
  6. } catch (FileNotFoundException e) {
  7.   e.printStackTrace();
  8. }

58 6316
Oralloy
988 Expert 512MB
Try building a method similar to ReadMyFile(), which returns a collection of valid accounts. The type of collection would, of course, depend on how you are planning to use the account numbers.

Expand|Select|Wrap|Line Numbers
  1. import java.util.Set;
  2. import java.util.HashSet;
  3.  
  4. public Set<Integer> ReadMyFile
  5. {
  6.   HashSet<Integer> result = new HashSet<Integer>;
  7.  
  8.   ...
  9.  
  10.   while( !eof )
  11.   {
  12.     ...
  13.     result.add(new Integer(validAccount));
  14.   }
  15.  
  16.   return result;
  17. }
Hopefully this helps a little.
Sep 13 '10 #2
I just want it to basically check from the validAccounts.txt file to see if the users input is a valid account.
Sep 13 '10 #3
Oralloy
988 Expert 512MB
Do you want to reload the file every time for the check, or just read the thing once?

Right now all you have are miscellaneous code bits that sort of solve your problem.

I take it that your assignment is to write a one-shot test to see if the account number is valid?

If you don't like the approach of returning a collection, then think procedurally.

You might use your current file read routine to test while reading - if no match is found by end-of file, then there is no match. (BTW, I notice that you are reading lines, not integer values. Were you planning on doing a comparison of strings or integers?)

You might hoist the file-read code to your isValid() method. Or even into the main routine.

If you need help converting text strings into integers, look up the documentation on Integer.decode(String).

Luck!
Sep 13 '10 #4
I have a two part assignment.
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner; 
  2.  
  3.    public class ChargeAccount 
  4.    { 
  5.       static int[] validChargeAccountNumbers = 
  6.       { 
  7.          5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 8080152, 
  8.          4562555, 5552012, 5050552, 7825877, 1250255, 1005231, 6545231, 
  9.          3852085, 7576651, 7881200, 4581002 
  10.          }; 
  11.  
  12.       public static void main(String[] args) 
  13.       { 
  14.          Scanner in = new Scanner(System.in); 
  15.  
  16.       // Ask the user for an account number 
  17.          System.out.print("Please enter an account number: "); 
  18.  
  19.       // Get the number from the user 
  20.          int number = in.nextInt(); 
  21.  
  22.       // Check to see if the number is valid 
  23.          if (ChargeAccount.isValid(number) == true) 
  24.          { 
  25.             System.out.println("That account number is valid."); 
  26.          } 
  27.  
  28.          else 
  29.          { 
  30.             System.out.println("You did not enter a valid account number."); 
  31.          } 
  32.       } 
  33.  
  34.    // Check to see if an account number is valid by comparing it to the entries in the array of valid numbers 
  35.       public static boolean isValid(int number) 
  36.       { 
  37.       // Perform sequential search through list of valid account numbers 
  38.          for (int i = 0; i < validChargeAccountNumbers.length; i++) 
  39.          { 
  40.          // Check to see if the number we were given is at the ith position in the list 
  41.             if (validChargeAccountNumbers[i] == number) 
  42.             { 
  43.                return true; 
  44.             } 
  45.          } 
  46.  
  47.       // If we get down here, then we never found it in the list 
  48.          return false; 
  49.       } 
  50.    }
  51.  
this works great. Now the second part is to read the valid accounts stored in the array above from a text file(valid_accounts.txt)
Sep 14 '10 #5
Oralloy
988 Expert 512MB
Well, you've made a good start at your reader code. Don't throw that away.

You already know that you need to replace the static instantiation of the account number array.

First, have you got a strategy? Will you look at the file until found, or will you read the entire file and then see if the value is there? This determines how you will write your program.

Second, have you looked at using any of the java.util collection classes to manage the account numbers? Or hasn't your instructor introduced you to template classes, yet?

Third, if you are lost, try pseudo-coding your answer - solve the problem with words first. Then you can write Java code to implement your solution.

Lastly, has your instructor given you any out-of-band information, like maximum file size, or some such? This is important, because the kinds of considerations in production software are a little tougher than are usually applied to students' assignments.

Cheers!
Sep 14 '10 #6
Ok i have it reading from the text file now but it is only outputing "the account you entered is invalid even when I input the correct account number.

Expand|Select|Wrap|Line Numbers
  1. import java.io.BufferedReader; 
  2.    import java.io.FileReader; 
  3.    import java.io.IOException; 
  4.    import java.util.Scanner; 
  5.    import java.util.Vector; 
  6.  
  7.    public class ChargeAccount 
  8.    { 
  9.       static Vector<Integer> validChargeAccountNumbers = new Vector<Integer>(); 
  10.  
  11.  
  12.       public static void main(String[] args) 
  13.       { 
  14.       //load the file
  15.          readMyFile("valid_accounts.txt"); 
  16.  
  17.          Scanner in = new Scanner(System.in); 
  18.  
  19.       // Ask the user for an account number 
  20.          System.out.print("Please enter an account number: "); 
  21.  
  22.       // Get the number from the user 
  23.          int number = in.nextInt(); 
  24.  
  25.       // Check to see if the number is valid 
  26.          if (isValid(number) == true) 
  27.          { 
  28.             System.out.println("That account number is valid."); 
  29.          } 
  30.  
  31.          else 
  32.          { 
  33.             System.out.println("You did not enter a valid account number."); 
  34.          } 
  35.       } 
  36.  
  37.    // Check to see if an account number is valid by comparing it to the 
  38.     // entries in the vector validChargeAccountNumbers 
  39.       public static boolean isValid(int number) 
  40.       { 
  41.          return validChargeAccountNumbers.contains(number); 
  42.       } 
  43.  
  44.       public static void readMyFile(String nameFile) 
  45.       { 
  46.          String record = null; 
  47.          BufferedReader reader = null; 
  48.          FileReader fr = null; 
  49.          int recCount = 0; 
  50.  
  51.       // Code to read the file and store each account into the vector 
  52.         // validChargeAccountNumbers 
  53.  
  54.       } 
  55.    }
  56.  
Sep 14 '10 #7
Oralloy
988 Expert 512MB
Excellent.

So now all you have to do is read from the file into your Vector, right?

The code is essentially the same as that you had earlier.

You're using a Scanner to read from the System.in stream, right?

What's wrong with using a Scanner to read from your account numbers file?

The only trick is detecting EOF, right? Scanner.nextInt() throws a java.util.NoSuchElementException exception on end-of-input. The page is here.

So the control code will look something like:
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.   while(true)
  4.   {
  5.     value = myScanner.nextInt();
  6.     validChargeAccountNumbers.add(value);
  7.   }
  8. }
  9. catch (NoSuchElementException exception)
  10. {
  11.   // EOF is legitimate; all others will pass up the stack
  12. }
Do you think you can do the rest?
Sep 14 '10 #8
actually no, I am late with this project. I have been working on it and have fallen behind in my other classes.
Sep 15 '10 #9
you mean something like this:

Expand|Select|Wrap|Line Numbers
  1.    import java.io.*;
  2.    import java.util.Vector;
  3.  
  4.    public class readMyFile 
  5.    {
  6.       public static void main(String[] args) 
  7.       {
  8.          DataInputStream dis = null;
  9.          String record = null;
  10.          int recCount = 0;
  11.          Vector<String> vAccounts = new Vector<String>();
  12.  
  13.          try 
  14.          {
  15.             File f = new File("valid_accounts.txt");
  16.             FileInputStream fis = new FileInputStream(f);
  17.             BufferedInputStream bis = new BufferedInputStream(fis);
  18.             dis = new DataInputStream(bis);
  19.  
  20.             while ( (record=dis.readLine()) != null ) 
  21.             {
  22.                vAccounts.add(record);
  23.                recCount++;
  24.                System.out.println(recCount + ": " + record);
  25.             }
  26.          } 
  27.  
  28.          // catch io errors from FileInputStream or readLine()
  29.             catch (IOException e) 
  30.             {
  31.                System.out.println("IOException error!" + e.getMessage());
  32.             } 
  33.  
  34.          finally 
  35.          {
  36.  
  37.          // if the file opened okay, make sure we close it
  38.             if (dis != null) 
  39.             {
  40.                try 
  41.                {
  42.                   dis.close();
  43.                } 
  44.                   catch (IOException ioe) 
  45.                   {
  46.                }
  47.             }
  48.          }
  49.       }
  50.    }
  51.  
Sep 15 '10 #10
Oralloy
988 Expert 512MB
Ouch. Then you are one frustrated kid.

Still, your code looks good. All you need is the read-file bit and you're done.

Did you ever bother to read that link I sent?

This is a simplified bit of code that might work for you, but it'll never fly in a production environment where people seem to put all kinds of junk in files. The problem is, of course, in error detection and reporting:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.   Scanner s = new Scanner(new File(fileName));
  3.  
  4.   while(s.hasNextInt())
  5.     validChargeAccountNumbers.add(s.nextInt());
  6. } catch (FileNotFoundException e) {
  7.   e.printStackTrace();
  8. }
Sep 15 '10 #11
lol very confused old man (44). I will try that.
Sep 15 '10 #12
Oralloy
988 Expert 512MB
Eeeep, that makes me ancient (48).
Sep 15 '10 #13
where would that go?
Sep 15 '10 #14
Oralloy
988 Expert 512MB
Do you understand what the code example does?
Sep 15 '10 #15
it looks like it reading from the file validChargeAccountNumber
Sep 15 '10 #16
ok so it should be in the readMyFile method?
Sep 15 '10 #17
Oralloy
988 Expert 512MB
Yep.

So that's probably the core of your method "ReadMyFile()".

What is important is how you incorporate it.

Since you're a student, I assume that you don't have any strong idea of exception handling, and how to use it. That's why the example (chicken-sh*t) exception handler.

At some level you'll have to deal with I/O errors in your program. You might just be able to declare all your methods as "throws Exception", and that's it. I really don't know what your instructor's exception handling requirements are.

Hopefully you can test and you'll be done in a couple minutes. Your post #7 looks pretty good, otherwise.
Sep 15 '10 #18
i get the error when i do it like that:
ChargeAccount.java:54: cannot find symbol
symbol : class File
location: class ChargeAccount
Scanner s = new Scanner(new File());
^
ChargeAccount.java:58: cannot find symbol
symbol : class FileNotFoundException
location: class ChargeAccount
catch (FileNotFoundException e)
^
2 errors
Sep 15 '10 #19
Oralloy
988 Expert 512MB
Ok, good start.

Did you remember to import the requisite classes. Either with the blanket imports:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.*;
or explicitly:
Expand|Select|Wrap|Line Numbers
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
BTW, is this your first or second Java program? *friendly-laugh*
Sep 15 '10 #20
he wanted us to us throws Exepction
Sep 15 '10 #21
not to sound ingorant but this is my second time taking the class. I got a D before. It is intro to Java.
Sep 15 '10 #22
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.Vector;
Sep 15 '10 #23
Im getting the scanner error now with this:

try {
Scanner s = new Scanner(new File());
while(s.hasNextInt())
validChargeAccountNumbers.add(s.nextInt());
}
catch (IOException ioe)
{
symbol : class File
location: class ChargeAccount
Scanner s = new Scanner(new File());
Sep 15 '10 #24
Oralloy
988 Expert 512MB
Sorry, was distracted by work there.

Try changing the declaration of your reader function to:

Expand|Select|Wrap|Line Numbers
  1. public static void readMyFile(String nameFile)
  2.   throws Exception
and drop the try/catch block.
Sep 15 '10 #25
ok did that and now it give me this error:

unreported exception java.lang.Exception; must be caught or declared to be thrown
readMyFile("valid_accounts.txt");
Sep 15 '10 #26
Oralloy
988 Expert 512MB
So add the same annotation to your Main function.

Either that, or Main will have to wrap all your code in a try/catch block, and handle the reporting. Does that make sense?
Sep 15 '10 #27
I appreciate all you help! here is the code i have now

Expand|Select|Wrap|Line Numbers
  1.  import java.io.BufferedReader; 
  2.    import java.io.FileReader; 
  3.    import java.io.IOException; 
  4.    import java.util.Scanner; 
  5.    import java.util.Vector; 
  6.  
  7.    public class ChargeAccount 
  8.    { 
  9.       static Vector<Integer> validChargeAccountNumbers = new Vector<Integer>(); 
  10.  
  11.  
  12.       public static void main(String[] args) 
  13.       { 
  14.       //load the file
  15.          readMyFile("valid_accounts.txt"); 
  16.  
  17.          Scanner in = new Scanner(System.in); 
  18.  
  19.       // Ask the user for an account number 
  20.          System.out.print("Please enter an account number: "); 
  21.  
  22.       // Get the number from the user 
  23.          int number = in.nextInt(); 
  24.  
  25.       // Check to see if the number is valid 
  26.          if (isValid(number) == true) 
  27.          { 
  28.             System.out.println("That account number is valid."); 
  29.          } 
  30.  
  31.          else 
  32.          { 
  33.             System.out.println("You did not enter a valid account number."); 
  34.          } 
  35.       } 
  36.  
  37.    // Check to see if an account number is valid by comparing it to the entries in the vector validChargeAccountNumbers 
  38.       public static boolean isValid(Integer number) 
  39.       { 
  40.          return validChargeAccountNumbers.contains(number); 
  41.       } 
  42.  
  43.       public static void readMyFile(String nameFile) throws Exception 
  44.       { 
  45.  
  46.          String record = null; 
  47.          BufferedReader reader = null; 
  48.          FileReader fr = null; 
  49.          int recCount = 0; 
  50.  
  51.  
  52.          //code to read the file and store each account into the vector validChargeAccountNumbers 
  53.          { 
  54.             Scanner s = new Scanner(new File()); 
  55.             while(s.hasNextInt()) 
  56.                validChargeAccountNumbers.add(s.nextInt()); 
  57.          } 
  58.        } 
  59.      }
  60.  
the ERROR:

ChargeAccount.java:54: cannot find symbol
symbol : class File
location: class ChargeAccount
Scanner s = new Scanner(new File());
^
Sep 15 '10 #28
Oralloy
988 Expert 512MB
The constructor for the File object in line 54 needs a file name, right?
Sep 15 '10 #29
Oralloy
988 Expert 512MB
BTW, lines 46-49 aren't doning anything useful, and the braces at lines 53 and 57 are extraneous.
Sep 15 '10 #30
ok did all that now I get this:

ChargeAccount.java:48: cannot find symbol
symbol : class File
location: class ChargeAccount
Scanner s = new Scanner(new File("valid_accounts.txt"));
Sep 15 '10 #31
thats right if a method have the throws then the main has to have it!
Sep 15 '10 #32
with this its like stuck in an infinite loop right?


Scanner s = new Scanner(new File());
while(s.hasNextInt())
validChargeAccountNumbers.add(s.nextInt());
}
Sep 15 '10 #33
Oralloy
988 Expert 512MB
not really. take a look at the Scanner.hasNextInt() method, you'll understand.
Sep 15 '10 #34
ok it just took a long time to compile. Its still doing what it originally did. any account number whether true or false it output false. So my guess is its not reading the file right?
Sep 15 '10 #35
how can I store it after I read the valid_accounts.txt?
Sep 15 '10 #36
Oralloy
988 Expert 512MB
What are you using to run Java? Just the command line compiler?

I just tried your program, edited as I observed, and it works just fine. Something else is going on.

So, you can interrogate the validChargeAccountNumbers array by using
Expand|Select|Wrap|Line Numbers
  1. for (int ix = 0; (ix < validChargeAccountNumbers.size()); ix++)
  2.   System.out.println("acct[" + ix + "] = " + validChargeAccountNumbers.get(ix));
Sep 15 '10 #37
JGrasp 1.8
Sep 15 '10 #38
Oralloy
988 Expert 512MB
Hmmm.

I haven't heard of it.

I'm using the Java 1.6 development environment from Sun underneath the Eclipse IDE.

As I noted - your program works for me. And when I use an incorrect file name, I get an exception telling me its not there.

Are you certain that the only thing in your valid_accounts file are integers separated by spaces?

I expect that if you have commas or other debris in there, you might have troubles.
Sep 15 '10 #39
Yes it runs but when i enter 5658845(a valid account number) it displays "You did not enter a valid account number." when it should display "That account number is valid."
Sep 15 '10 #40
Oralloy
988 Expert 512MB
Did the account number show up in your diagnostics list?
Sep 15 '10 #41
this is in valid_accounts.txt

5658845
4520125
7895122
8777541
8451277
1302850
8080152
4562555
5552012
5050552
7825877
1250255
1005231
6545231
3852085
7576651
7881200
4581002
Sep 15 '10 #42
this is what shows up:

----jGRASP exec: java ChargeAccount

Please enter an account number: 5658845
You did not enter a valid account number.

----jGRASP: operation complete.
Sep 15 '10 #43
Oralloy
988 Expert 512MB
Odd, it looks like the first in the list.

At this point, I'm not sure why you're not seeing the correct response.

Try printing out the actual value you read in.

Expand|Select|Wrap|Line Numbers
  1. System.out.println("number = " + number);
Sep 15 '10 #44
yeah its the first...Have it memorized now lol. I used the System.out.println("number = " + number); got error number symbol not found. then i used the

//code to read the file and store each account into the vector validChargeAccountNumbers
{
Scanner s = new Scanner("valid_accounts.txt");
while(s.hasNextInt())
validChargeAccountNumbers.add(s.nextInt());
for (int ix = 0; (ix < validChargeAccountNumbers.size()); ix++) System.out.println("acct[" + ix + "] = " + validChargeAccountNumbers.get(ix));
System.out.println("number = " + validChargeAccountNumbers);

}
and i get

----jGRASP exec: java ChargeAccount

number = []
Please enter an account number: 5658845
You did not enter a valid account number.
Sep 15 '10 #45
so based on number = [] its not reading the file right?
Sep 15 '10 #46
Oralloy
988 Expert 512MB
Well, if the list didn't print, then something is wrong.

Look at where you are creating the Scanner object.

Do you know what that means in the documentation?

The line should be:
Expand|Select|Wrap|Line Numbers
  1. Scanner s = new Scanner(new File("valid_accounts.txt"));
Otherwise, it will try to scan the input string "valid_accounts.txt", which, of course, contains no valid integer values.

Why did you eliminate the "new File" from the code I posted?
Sep 15 '10 #47
ok lets start fresh. This is my orignal program:
Expand|Select|Wrap|Line Numbers
  1.    import java.util.Scanner; 
  2.  
  3.    public class ChargeAccount1 
  4.    { 
  5.       static int[] validChargeAccountNumbers = 
  6.       { 
  7.          5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 8080152, 
  8.          4562555, 5552012, 5050552, 7825877, 1250255, 1005231, 6545231, 
  9.          3852085, 7576651, 7881200, 4581002 
  10.          }; 
  11.       public static void main(String[] args) 
  12.       { 
  13.          Scanner in = new Scanner(System.in); 
  14.  
  15.       // Ask the user for an account number 
  16.          System.out.print("Please enter an account number: "); 
  17.  
  18.        // Get the number from the user 
  19.          int number = in.nextInt(); 
  20.  
  21.       // Check to see if the number is valid 
  22.          if (ChargeAccount1.isValid(number) == true) 
  23.          { 
  24.             System.out.println("That account number is valid."); 
  25.          } 
  26.  
  27.          else 
  28.          { 
  29.             System.out.println("You did not enter a valid account number."); 
  30.          } 
  31.       } 
  32.  
  33.    // Check to see if an account number is valid by comparing it to the entries in the array of valid numbers 
  34.       public static boolean isValid(int number) 
  35.       { 
  36.  
  37.       // Perform sequential search through list of valid account numbers 
  38.          for (int i = 0; i < validChargeAccountNumbers.length; i++) 
  39.          { 
  40.  
  41.          // Check to see if the number we were given is at the ith position in the list 
  42.             if (validChargeAccountNumbers[i] == number) 
  43.             { 
  44.                return true; 
  45.             } 
  46.          } 
  47.         return false; 
  48.       } 
  49.    } 
  50.  
Sep 15 '10 #48
because it gave the error:

ChargeAccount.java:48: cannot find symbol
symbol : class File
location: class ChargeAccount
Scanner s = new Scanner(new File("valid_accounts.txt"));
^
1 error
Sep 15 '10 #49
Oralloy
988 Expert 512MB
Actually go to the code from post #28, and fix line #54 by placing the correct file name in the line where you create the Scanner.

That gave you the error "Can't find class File", right?

Well, you need to import File to resolve that - specifically the class java.io.File.
Sep 15 '10 #50

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Thomas Matthews | last post by:
Is there anything technically wrong with the code below? I compiled it with g++ 3.3.1 and it executes with no errors. I compiled it with bcc32 5.6 and it executes with "This program has performed...
0
by: cherry | last post by:
Dear All, I have written a program in sharepoint, in which will call a Web Service of another Sharepoint portal server so that documents from sharepoint portal server A can push document to...
5
by: ComicCaper | last post by:
Hi all, I use a quiz program that accepts a text file for questions and answers in this format: Question Answer1 <----is the correct answer. Quiz randomizes answers. Answer2 Answer3...
1
by: Glenn Graham | last post by:
My web download program stopped working when IE7 beta 1-3 was installed. Error when calling OpenRequest in CHttpConnection. The Error is Created by ASSERT(hFile != NULL) in mehtod...
0
by: jisha | last post by:
i want to get code for a program in visual c++ where : 1]take the name of directory say DIR 2]get a file ,say IN from that directory which has 3 column (say X, Y and Z) and many rows( display this...
4
by: gdarian216 | last post by:
I am doing a multi file program and I got it to work correctly in a single file but when I split it up it isn't working properly. I keep getting errors when i compile. Can anyone help me figure out...
1
by: gdarian216 | last post by:
I am writing a multifile program and it worked when it was all in one file. I have gotten all of the errors out of the program except when I go to output the change the quarters are right but the...
1
by: sadanand | last post by:
Hi, I am a beginer to perl progmig. When I run the following program.. use File::Find; use File::Stat; use Time::Local;
2
by: rajak20pradeep | last post by:
Hello, i cannot solve this program. Q. Write a program to find and count article(a.an ,the) in a text file .
1
by: sunny | last post by:
Hi all We have a pdf user manual which we open when client clicks on help button. some of our clients have the issue that it does not open the file and it says file not found. checked with...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.