Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you want to back up a huge file to a CD-R. You can do this by splitting

ID: 3817846 • Letter: S

Question

Suppose you want to back up a huge file to a CD-R. You can do this by splitting the file into smaller pieces and backup up those pieces separately. Write a utility program named FileSplitter that splits a large file into smaller ones. Develop a GUI interface to select the file and the number of smaller files for splitting it up. Below is an example of what such a GUI display might include.

File Splitter f you split a file named temp.txt into 3 smalle files the three smaller files are temp.txt.1, temp.txt.2, and temp.txt.3 Enter or choose a file: Specify the number of smaller files Start

Explanation / Answer

Here is the java code for the above scenario

import java.io.*;

public class File_splitter {

public static void main(String[] args) throws IOException {

if (args.length != 2) {

System.out.println("Usage: File_splitter SourceFile numberOfPieces");

System.exit(1);

}

int numberOfPieces = Integer.parseInt(args[1]);

RandomAccessFile[] splits = new RandomAccessFile[numberOfPieces];

try (RandomAccessFile inout = new RandomAccessFile(args[0], "r");)

{

for (int i = 0; i < splits.length; i++) {

splits[i] = new RandomAccessFile(args[0] + "." + (i + 1), "rw");

}

int size = Math.round(inout.length() / numberOfPieces);

int count = 0;

byte[] b;

for (int i = 0; i < numberOfPieces - 1; i++)

{

inout.seek(count * size);

b = new byte[size];

inout.read(b);

splits[i].write(b);

count++;

}

inout.seek(count * size);

b = new byte[(int)inout.length() - (count * size)];

inout.read(b);

splits[numberOfPieces - 1].write(b);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote