>>>
The File chopper takes one file as an input and divides it into a number of files
each file containing x lines. The interface takes the file name as input and the
number of lines, each of the output files should contain. For example, if you give a
file with 20 lines as input and enter 4 as number of lines. Then 5 files will be
generated, each containing only 4 lines of the input file.
My question is how to divide the file to a few lines and I want to create a new file to keep the lines divided by the number that the user enter it
Note that FileReader and FileWriter use the platform default encoding, so make sure that's what the text files use. If they use some other encoding, then you'd have to use FileInputStream and InputStreamReader instead of FileReader, and the corresponding classes for writing the file. Those allow you to specify the encoding explicitly.
Note that FileReader and FileWriter use the platform default encoding, so make sure that's what the text files use. If they use some other encoding, then you'd have to use FileInputStream and InputStreamReader instead of FileReader, and the corresponding classes for writing the file. Those allow you to specify the encoding explicitly.
Hello .. Thank you to help you but I know this
This is my program and started it, but I have remaining small problem ..
How do I link the counter (longer lines of the file) to the number entered by the user so divided by it and creates a new file on the numbering.
The number of files that you need to create is the total # of lines from the source file divided by the number of lines the user wants per file. So you would just need to loop through the source file that number of lines and write those to a different file.
Hunter
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
You should be able to count the lines as you read, and create new files as you go.
Sorry if I make wrong here . But I just try to help Shaza.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
apologies accepted
shaza smart
Greenhorn
Joined: May 21, 2011
Posts: 5
posted
0
Thank you all
I do not want a solution because it's my project and I want to resolve it myself, but because the Boost time my thoughts really confused and I can not focus
1. Write code that will read the data from one file and write it to another, one line at a time. Once you have that is is simpler to modify to get what you want.
2. Next modify the code to keep a count of the rows as you add them to your file.
3. Modify so that when the count reaches a certain number it closes your current output file, creates a new file with a different filename resets the count and starts writing to the new file. (You may want filenames such as file1.txt, file2.txt... so on, so you may want to also keep a count of which file you were on)
Try this, if you are having trouble while following this then post the appropriate code and we will help you based on that.