473,385 Members | 1,492 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,385 software developers and data experts.

Help with line count

Hi, I am having problems with this bit of code:


public class main
{


public class readAccounts
{
reader1 r = new reader1();

}

void readAccounts()
{
printFile("account.txt");
}
static void printFile(String fileName)
{
System.out.println();

String[] lines = LineIO.readAllLines(fileName);
for (String l : lines)

{
System.out.println(l);
}
}
public static void main(String[] args)
{
for (String arg : args)
{
printFile(arg);
}
}
// print number of lines


private static void count(String name)
{
long numLines = 0;
String lines;
do {
lines = LineIO.readAllLines(fileName);
if (lines != null)
{
numLines++;


}
}
while (line != null);
System.out.println(numLines)

}}

The basic function is to read a text document then display the document with the amount of lines in the text file. So far it works fine if the print lines code is taken out. It will display the text document perfectly. However when the new code is added I get an error message saying that 'cannot find symbol = variable file name'

Im sure this is simple to rectify and any help would be welcomed

Thankyou
Dec 9 '06 #1
3 2163
DeMan
1,806 1GB
in your count method, you pass in a String called name, and then try to readAll fileName, you might like to change one of them.

What is the while loop doing down the bottom? (it loops while line!=null BUT I don't think it can see line (in which case it won't run), nor is line being modified (so it will run forever), and finally it has a semi-colon behind it (so it won't do aything). Are you trying to run multiple threads or something (or did this accidently slip in).....?
Dec 10 '06 #2
DeMan
1,806 1GB
Sorry, the do...while structure caught me out - nonetheless I think it should be lines not line......(you can ignore the rest of what I said...I wasn't looking properly.
Dec 10 '06 #3
r035198x
13,262 8TB
Sorry, the do...while structure caught me out - nonetheless I think it should be lines not line......(you can ignore the rest of what I said...I wasn't looking properly.
When posting code please use code tags so that your code is readable.

This method will not compile because you are using the variable fileName which is neither declared nor passed into the method.

Expand|Select|Wrap|Line Numbers
  1.  private static void count(String name) { 
  2.  long numLines = 0;
  3.  String lines;
  4.  do {
  5.    lines = LineIO.readAllLines(fileName);  //fileName is unknown here
  6.    if (lines != null) {
  7.      numLines++;
  8.    }
  9.  }
  10.  while (line != null);
  11.  System.out.println(numLines)
  12. }
  13.  
Dec 11 '06 #4

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

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
5
by: ducky801 | last post by:
Hi all. When i run the code below i get a 'NullReferenceException was unhandled' error. I am using VB 2005 Express. I'm confused about this because, I have declared my array and i'm trying to...
4
by: J | last post by:
I've spent most of the day on this, and I just can't seem to find a solution, please help me! :) I'm recieving XML that I can't modify that looks like: <?xml version="1.0"?> <Doc> <Page>...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
1
by: yajna | last post by:
its a program that converts characters to the next character of the alphabet i want to create am infinite loop for this program..that is make the program accept many inputs...how do i do it? n how...
2
by: muppetjones | last post by:
I have been receiving a "Floating point exception" from Perl after my program has run several iterations. I have not been able to pin point the location of the error, and I am clueless. Especially as...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
2
by: embz | last post by:
this post concerns three pages. 1. this page: http://www.katherine-designs.com/sendemail.php i get the following errors: a lot of it seems to deal with the PHP code i inserted to the page....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.