Basically, I need to write a program that takes a user input for multiple text files, and then prints them out into one file.
I usually try not to pose questions here back to back, but alas, I need the help this time round. What really has me baffled is the start of the code I was given to work with. It has many lines that I'm not sure what the actual use is, or how I'm supposed to work with them.
Here is the code:
import java.io.IOException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* This program concatenates contents of several files into one file.
*/
public class CatFiles
{
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner(System.in);
int j = 0;
boolean done = false;
while(!done)
{
System.out.print("Enter input file: ");
if(in.nextLine().toLowerCase().equals("q"))
{
System.out.print("Enter Destination file: ");
String output = in.next();
PrintWriter writer = new PrintWriter(output);
done = true;
}
else
{
String input = in.next();
}
}
if (args.length < 2)
{
System.out.println(
"Usage: CatFiles sourcefile1 sourcefile2 . . . targetfile");
return;
}
String target = args[args.length - 1] ;
for (int i = 0; i < args.length - 1; i++)
{
String source = args[i];
}
}
}