*
The moose likes Beginning Java and the fly likes Line by line counting of characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Line by line counting of characters" Watch "Line by line counting of characters" New topic
Author

Line by line counting of characters

Aasha Karthik
Greenhorn

Joined: Jun 07, 2013
Posts: 1
Hi all,

This is my first post on joining the forum. I feel encouraged that there are people out there to discuss and help.
I have been trying to create a mini project that takes an input file text file and performs some string manipulations on it using java code and stores the updated contents in an output file.

String manipulations:
1.Count the no of characters in each line.
2.Count the number of 4's in each line.
3.Replace 'this' with 'that'
4.Reverse line by line

My code prints the total number of characters and 4's in the file and not line by line. Could anyone suggest me on this please.

My function for counting number of 4's:


My function for counting total number of characters:



My main function is:


Also I would like the result from file1.replaceString(file1.copy()); in my main function to be passed as an argument to the following reverse function in main like file1.reverse(file1.replaceString(file1.copy())); But it wouldn't work. T

Thank you.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Aasha Karthik wrote:This is my first post on joining the forum...

Welcome to JavaRanch Aasha.

First: When you're posting code, please UseCodeTags (←click). I've added them for you this time; see how much better it looks?

Also: avoid very long lines, and make sure your code is indented properly after you've pasted it. Yours is a bit off, but you can use the 'Edit' button to clean it up if you like, and the 'Preview' button to see what it will look like before you post. I'd also suggest NOT using tabs for indentation.

Thanks

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Aasha Karthik wrote:My function for counting number of 4's:...

It seems a bit specific to me. What if you wanted to change your program to count '5's instead? Or 4's AND 5's? Can you think how you might make that method a bit more generic?

It also contains almost identical code to your countChar() method
Can you think how you might join the two together?

Also: What is FileRead? I don't see any sign of such a class.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Line by line counting of characters
 
Similar Threads
find out digits and spaces in String
adding String Array in .conf(text also) file after particular line by java?
Help with Character count from a file.
can some one help me im just new in java.
Java Word Count