7 Years
Discussion Span
Last Post by Katana24

Hello & welcome to Dani Web. Your text file is very long; you can't possibly expect someone to read through it can you? If you want to count something in a text file, like the number of nodes, then you need to first read the text file. You would then need to use an if statement to check whether the current line contains the keyword 'NODE' or whatever it is that represents a node or message flows.
In practice there are numerous ways of doing this, like using an array or using vectors:

public static void readFromFile(String fileToReadFrom)
		try {
			int lineCount = 0;
			// Used to read from a file
			BufferedReader myFile = new BufferedReader( new FileReader( fileToReadFrom ) );
			String str;
			// This makes sure that the line it reads actually contains a value before moving on
			while( ( str =  myFile.readLine() ) != null )
				int limit = str.length();
				int numSpaces = 0;
				char [] myArray = new char[ limit ];
				for( int i = 0; i < limit; i++)
					// == used to compare two characters
					myArray[i] = str.charAt(i);
					if( myArray[i] == ' ' )
				System.out.println( "Number of Spaces = "+numSpaces );
		    System.out.println(fileToReadFrom+" contain's "+lineCount+" lines");
		    // If there is nothing in the try block then there will be an error message in the catch line
		} catch (IOException e) 
				JOptionPane.showMessageDialog( null, "Error: "+e.getMessage() );

In the code above I am counting the number of spaces in each line. Each line occupies the array when it moves. You could use the same method, with a-bit of tweaking to count the word NODE. This should hopefully get you started :P

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.