why doesnt this work i get null values any suggestions? thanks. -
-
if (event.getSource() == submit)
-
{
-
try {
-
BufferedReader in = new BufferedReader(new FileReader("names.txt"));
-
if (counter < 3)
-
{
-
namestring = in.readLine();
-
System.out.println(namestring);
-
namearray[a] = namestring;
-
//namearray.add(a,namestring);
-
counter++;
-
a++;
-
}
-
else if (counter > 3)
-
{
-
idstring = in.readLine();
-
-
-
idint = Integer.parseInt(idstring);
-
// idarray.add(b,idstring);
-
idarray[b] = idint;
-
counter++;
-
b++;
-
}
-
-
-
in.close();
-
for(int a = 0; a< 3; a++)
-
{
-
System.out.println(namearray[a]);
-
}
-
for(int b = 0; b< 3; b++)
-
{
-
System.out.println(idarray[b]);
-
}
-
5 1066
What do you do when counter ==3?
kind regards,
Jos
oh. thats an error. would i make the second one >2?
oh. thats an error. would i make the second one >2?
If a number is *not* < 3 it is >= 3; < and >= are complementary; try it with a
couple of examples.
kind regards,
Jos
the txt looks like this
greg
john
joe
54343
45777
33444
i run this program, and it displays
greg
greg
null
0
0
0
whats up? thanks. - if (event.getSource() == submit)
-
{
-
try {
-
BufferedReader in = new BufferedReader(new FileReader("names.txt"));
-
if (counter <= 3)
-
{
-
namestring = in.readLine();
-
-
namearray[a] = namestring;
-
//namearray.add(a,namestring);
-
counter++;
-
a++;
-
}
-
else if (counter > 3)
-
{
-
idstring = in.readLine();
-
-
-
idint = Integer.parseInt(idstring);
-
// idarray.add(b,idstring);
-
idarray[b] = idint;
-
counter++;
-
b++;
-
}
-
-
-
in.close();
-
for(int a = 0; a< 3; a++)
-
{
-
System.out.println(namearray[a]);
-
}
-
for(int b = 0; b< 3; b++)
-
{
-
System.out.println(idarray[b]);
-
}
-
-
} catch (IOException e) {
-
}
You do realize that you're opening a new BufferedReader everytime you press
that button don't you? A new BufferedReader starts reading from the start over
and over again.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Raymond Hettinger |
last post by:
Found in a pamphlet at a pre-school:
---------------------------------------
Reading improves vocabulary
Reading raises cultural literacy through shared knowledge
Reading develops writing skills...
|
by: sahukar praveen |
last post by:
Hello,
I have a question.
I try to print a ascii file in reverse order( bottom-top). Here is the logic.
1. Go to the botton of the file fseek(). move one character back to avoid the EOF.
2....
|
by: KevinD |
last post by:
assumption: I am new to C and old to COBOL
I have been reading a lot (self teaching) but something is not sinking
in with respect to reading a simple file - one record at a time.
Using C, I am...
|
by: Gaijinco |
last post by:
I had a file named nap.in which looks like this:
4
10:00 12:00 Lectures
12:00 13:00 Lunch, like always.
13:00 15:00 Boring lectures...
15:30 17:45 Reading
4
10:00 12:00 Lectures
12:00 13:00...
|
by: The Cool Giraffe |
last post by:
Regarding the following code i have a problem.
void read () {
fstream file;
ios::open_mode opMode = ios::in;
file.open ("some.txt", opMode);
char *ch = new char;
vector <charv;
while...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
| |