473,848 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with line count

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


public class main
{


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

}

void readAccounts()
{
printFile("acco unt.txt");
}
static void printFile(Strin g fileName)
{
System.out.prin tln();

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

{
System.out.prin tln(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.readAllL ines(fileName);
if (lines != null)
{
numLines++;


}
}
while (line != null);
System.out.prin tln(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 2197
DeMan
1,806 Top Contributor
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 Top Contributor
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 MVP
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
3934
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 them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
6
391
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 hides all of them including hiding the database window, disabling menu changes. What I am after is the same effect as disabling all the check boxes in startup which still leaves 'File', 'Edit', 'Insert','Records','Window' &'Help'. I want to do this...
6
2888
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 suggestion for improvements or conversion to iteration would be much appreciated
5
6607
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 put things in it, so shouldn't it BE NULL until i start to put things in it? I'm kind of new to this so hoepfully i'm just overlooking something easy. I know my code is actually talking to the DB (or dataset rather) because the messageboxes work....
4
1474
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> <Item Value="A" Id="1" Count="1"/> <Item Value="B" Id="2" Count="1"/>
7
2865
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 found a bug that I can't figure out (believe me; I've tried everything and asked for help several times on the IRC-channel). The updateMsg() and iMsg() takes a list of message-lines as argument (or process a string to a list), and it'll output...
1
1258
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 should i modify the code such that it accepts only alphabets and not numbers...and display an error message in case on numbers #include <stdio.h> main() {
2
2578
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 I can't seem to find exactly what this exception means. 1) What is a floating point exception? 2) What causes it? 3) Is there any way to fix it? I have included my code below, but as there is quite a bit any suggestion of how to handle...
4
6350
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 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
2
6363
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. as my PHP skills are close to nil, i'm wary about fiddling with it myself. =\ 2. now this page: http://www.katherine-designs.com/contact.php
0
9735
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10997
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10661
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10718
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9497
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7067
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4134
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3172
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.