cat *.java using java interface
1 posts in topic
Flat View  Flat View

Posted By:   Raj_Mantena
Posted On:   Saturday, August 9, 2003 07:44 PM

Why can't you do “cat *.java” as a command and option and get the desired output?

for example : if u type cat *.java in Unix $ prompt then it will display u all .java files on consol.
If u try same thing from java application (if u have JSpinner Box and option box then select cat in JSpinner and *.java in option box and click on some command button) then it wont works. why? (it's simple programm dont use any file permissions)

Re: cat *.java using java interface

Posted By:   David_Bates  
Posted On:   Sunday, August 10, 2003 02:22 AM


OK. I understand the command "cat *.java" in unix/linux. This will display the contents of all the Java files in the current directory. Fine.

Next, you start talking about some Swing application that I've never heard about. All you explain is the user interface and how the user selects the command, nothing about how the user request is actually executed!

Please be more specific!

If I was to write "cat" in Java, it'd look something like this:

import java.io.*;

public class Cat {
public static void main(String[] args) throws IOException {
// Loop through each file...
for (int i = 0; i < args.length; i++) {

public static void display(String fileName) throws IOException {
File f = new File(fileName);

// Check the file actually exists...
if (!f.exists()) {
System.out.println("File '" + fileName + "' does not exist.");
// Check the file isn't a directory...
else if (f.isDirectory()) {
System.out.println("'" + fileName + "' is a directory and cannot be displayed.");

// Read and display the contents of the file.
BufferedReader br = new BufferedReader(new FileReader(f));
String line = br.readLine();
while (line != null) {
line = br.readLine();

About | Sitemap | Contact