I'm trying to combine 2 files into 1. Please help
I need to take 2 different files and combine them into 1 file. This is what I have so far, but I'm doing something wrong. The error I get is java.util.NoSuchElementException: No line found (in java.util.Scanner) on this line 'String line2 = file2.nextLine();' Also I have stuff in the file but everytime this runs my file empties. Please help, I'm stuck! Here is my code.
Re: I'm trying to combine 2 files into 1. Please help
Your code needs to test that both Scanner objects has a next line. You are only testing one.
You are assuming that the first file does not have more lines than the second file.
Re: I'm trying to combine 2 files into 1. Please help
Ok, I added another "while" for the 2nd file. I found in my main a piece of code that should not have been there that was erasing my answers file. Otherwise, there would've been the same number of lines in both. Because my 2nd file was being erased, that is why this code wasn't working. Thanks for your advice on testing the second file.
Re: I'm trying to combine 2 files into 1. Please help
I'm trying to combine 2 files into 1. Please help
when using file writer there is a way to tell it to append the file. (aka, add to the end of what is already there instead of overwriting it.)
look up append to a file, if you don't need to evaluate or combine the data in the files.