A program to split a large text file (> 6MB) in Java

I’m sure there are utilities/downloads available on the net, but I’d like to write a program using Java instead. My boss has asked me to split a text file for one of our developers so that we can send it through our internal ticketing system, and so that it isn’t so damn large for her to read (file is a little over 600MB).

Can someone help me write this program? I’m trying to get into the practice of writing every day, and have finally found a program that I need to write that would be helpful to myself and my work. Someone once told me that programming is addictive as playing video games, and I thought they were out of their mind, but come to find out, they’re 100% correct.

If you know how to work with files, this should be easy.

Set some threshold for the max size of any file you’re splitting into. Then, either line-by-line or character-by-character, read from the huge file and write to the new file until the amount you’ve written exceeds the threshold (general rule of thumb is 1 character = 1 byte, except on Windows, where a newline is usually \r\n). When you hit the threshold, reset your counter and move on to a new file.

(as a note: I won’t flag this as off-topic because this is probably just as interesting as many of the cakewalk problems we have here)

Off-topic?

It’s not relevant to CodeChef, its contests, its problems, or really algorithms in general. This would be better suited for StackOverflow or something, but I don’t mind answering things anyway.

I have the following (I’m new to programming and only have the very basics, and not well too boot):

	public static int[] readFiles(String file) {

		try {
			File f = new File(file);
			Scanner in = new Scanner(f);
			int ctr = 0;
			while (in.hasNextInt()) {
				ctr++;
				in.nextInt();

			}
			in.close();

			int[] arr = new int[ctr];

			Scanner in1 = new Scanner(f);

			for (int i = 0; i < arr.length; i++) { // looping the array.
				arr[i] = in1.nextInt(); // placing the integer from the file into the array.

			}
			in1.close();
			return arr;
		}

This is from my final that I took for the Advanced Java class. I’m not sure how to further write the program. I know half the battle is setting down and to start the process, but I’m not sure where else to go.

I also know that I don’t need

int[] arr = new int[ctr];

			Scanner in1 = new Scanner(f);

			for (int i = 0; i < arr.length; i++) { // looping the array.
				arr[i] = in1.nextInt(); // placing the integer from the file into the array.

			}
			in1.close();
			return arr;

Well, what do you need to do? Start by writing out some pseudocode (ignore the file mumbo jumbo), or something, if it’s too hard to do it all at once.

TXT_splitter

MAIN
BEGIN

    String string = readFiles("text.txt:);
   
    try{
          PrintWriter writer = new PrintWriter("output.txt");
          writer.close();

     }
    catch(FileNotFoundException e){

          e.printStackTrace();
          System.exit;
 }