Results 1 to 6 of 6
- 04-26-2012, 12:16 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 25
- Rep Power
- 0
pass input file to class from console
At the moment I have a java program which reads a text file and does certain operations with its contents.. how do I change this:
..so that I can give the file to the program directly from the console, like so:Java Code:scan = new Scanner(new FileReader(inputtextfile.txt))
java myProgram inputtextfile.txt
- 04-26-2012, 12:22 PM #2
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
Re: pass input file to class from console
System.in is stdin, which is where your console input comes from.
Java Code:BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input; input = in.readLine();
- 04-26-2012, 12:37 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 25
- Rep Power
- 0
Re: pass input file to class from console
So I cannot use Scanner for this??
- 04-26-2012, 12:44 PM #4
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
Re: pass input file to class from console
Well, I showed you a way to use it, think about how you can take that information and use it with Scanner.
- 04-26-2012, 01:52 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: pass input file to class from console
They want to supply the filename at teh command line, not read input from Sys.in.
For the OP...parameters like your filename are what exist in the args parameter on the main() method.
In your example args[0] would contain the value "inputtextfile.txt", which you can pass into the line creating the Scanner instead of the hardcoded filename.Please do not ask for code as refusal often offends.
- 04-26-2012, 02:00 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
How to get input from Console
By karma in forum New To JavaReplies: 8Last Post: 08-13-2010, 09:32 PM -
who to take user input ,not by console...
By Shyam Singh in forum New To JavaReplies: 3Last Post: 06-13-2008, 10:09 PM -
how to take input from console in jsp
By veena in forum New To JavaReplies: 1Last Post: 05-06-2008, 04:39 AM -
ways to get input from console
By soni in forum New To JavaReplies: 2Last Post: 05-05-2008, 09:44 PM -
How to read input from console
By Java Tip in forum java.ioReplies: 0Last Post: 04-16-2008, 10:57 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks