Microsoft
Software
Hardware
Network
Question : How do I use a user input filename and then read line by line
I am really new to Java and am feeling quite challenged at the moment! :)
I need to allow the user to input the filename to read from, so I'm using a scanner:
try{
Scanner in = new Scanner(System.in);
System.out.print("Enter name of input file: ");
Scanner input=new Scanner(new FileReader(in.nextLine()))
;
if(!input.hasNext())
{System.out.println("File Empty - aborting");
System.exit(0);}
while (input.hasNextLine())
{
After reading the input file, I need to count the characters and output the number of chars per line into a text file (so the number of lines in the source file will match the output file). I think I need to use BufferedInputStream to read it line by line, but I'm not sure how to use it with the scanner, or if what I have above is good enough. All the examples I have found used a static file name with BufferedInputStream.
Thanks!!!
Answer : How do I use a user input filename and then read line by line
no need for a scanner, see the following for how to read the file
http://helpdesk.objects.co
m.au/java/
how-do-i-r
ead-a-text
-
file-line
-by-line
Random Solutions
DHCP SERVICE CAUSING HAVOC IN WIN XP
How to change the Administration server on a domino domain?
Network performance issue...
Windows XP IP Configuration
Moving Computers to OUs
Configuring Cisco wireless access points for seamless roaming
NetGear FVS328 & ProSafe VPN Client - DNS Problem?
How can I limit the broadband speed on my computer for other persons ?
ISP Change / MX Records
What are the correct Pointer Records that need to be setup.