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
i need to disable chatting on wireless modem.
Netsh - script to check DHCP enabled
Cable Broadband Wireless Internet via another Wireless Router
Document not found
static and a dynamic ipaddress assigned to the same NIC at the same time?
Move files/folders in NTFS and KEEP PERMISSIONS/SHARING/SECURI<wbr />TY! settings
Cisco UC 500 - how to divert main number to a mobile
Cable Modem
Create an upload folder accessible to all users
Event ID 7062