Concatenate files
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class Cat {
public static void concatenate(String fileName) {
RandomAccessFile file = null;
String line = null;
try {
file = new RandomAccessFile(fileName, "r");
while ((line = file.readLine()) != null) {
System.out.println(line);
}
return;
} catch (FileNotFoundException fnf) {
System.err.println("File: " + fileName + " not found.");
} catch (Exception e) {
System.err.println(e.toString());
} finally {
if (file != null) {
try {
file.close();
} catch (IOException io) {
}
}
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++)
Cat.concatenate(args[i]);
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
IO File:
- Compare File Dates
- Compress files using with ZIP
- Concatenate files
- Copy a File with NIO FileChannel and ByteBuffer
- Copy a file with FileReader and FileWriter
- Copy a file with InputStream and OutputStream
- Copy a file and overwrite
- Delete a file
- Delete File Recursively
- Get readable file size
- Move a file
- Rename a file
- Report a file's status
- Search a file by regular expressions
- Touch a file: set File Last Modified Time