473,781 Members | 2,335 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 2193
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
3930
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
2882
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
6600
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
1470
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
2854
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
1256
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
2575
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
6341
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
6359
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
10139
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
10075
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
9931
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
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...
1
7485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
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();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.