This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Merge two text files and count number of characters. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Merge two text files and count number of characters." Watch "Merge two text files and count number of characters." New topic

Merge two text files and count number of characters.

Grey Joseph

Joined: May 24, 2014
Posts: 1
So here's a bit about the details.
I need to read the contents of file A, and B and store it in file C by joining the contents of A and B and also counting the number of letters/characters present in it.
I've come up with this so far.
Can someone help me here.
Any input would be great.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31683

Welcome to CodeRanch!

If you are using Java 7, there is an easier way to do this. I'll assume that you aren't (or this is a homework assignment and you haven't learned the Java 7 way of reading a file yet.)

Let's start with one thing at a time. Making the code compile. In future posts, it helps to say what the errors are from the compiler. You've got a number of them. It helps to write code in smaller pieces and fix the errors as they come up. Let's start with this smaller version of your code.

Can you fix the compiler errors and run it to output "2"? I see five compiler issues and a logic error. Give it a shot. Try to fix the errors your compiler gives you one at a time. When you hit one that you don't know what to do with, copy the error and post it as a reply to this thread. Once you fix the compiler error, see if you explain the logic error. Even if you can't fix all of these, the process will help you learn more about Java and help you with future programs. And don't worry, we are hear to hold your hand.

Here's a hint to start: Java is case sensitive. See anything about "string" that's different in your code than the example you started with?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Merge two text files and count number of characters.