File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Suppling the name of the file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Suppling the name of the file" Watch "Suppling the name of the file" New topic

Suppling the name of the file

Arthur Zadrozny

Joined: Sep 19, 2002
Posts: 3
Hi, I am new here and I have question which might seem a little easy. I am writting a program which reads in a text file and the user needs to supply the name of that text file. How do I do that? Here is some code that might help. Thanks.
final static String FIRST_FILE = "the_open_window.txt";
public static void main (String [] args)
try {
Reader r = new BufferedReader (new FileReader(FIRST_FILE));
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Arthur,

So if the name of your application is ReadSomeFile then the user might open start the application like:
java ReadSomeFile foo.txt
and the application should attempt to open the file named foo.txt in the current directory.
Hope this helps,
Michael Morris

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: Suppling the name of the file
It's not a secret anymore!