Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Read from a file loop question

EDIT: Just figured out one problem. Now how do i manage to use this input to now send this to an output file in a formatted way? I need to use printstream but will i put it within the try statement?

Code
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;

public class Standalonereport {

    public static void main(String[] args) {
        
        String fileName;
        String outFile;
        
        
        Scanner keyboardScanner = new Scanner(System.in);
        
        System.out.printf("Enter the file name: ");
        
        fileName = keyboardScanner.next();
        
        System.out.printf("Enter the output file name: ");
        
        outFile = keyboardScanner.next();
        
        try
        {

        Scanner inputScanner = new Scanner(new File(fileName));

        while (inputScanner.hasNextLine())

            {
            String i = inputScanner.nextLine();
            System.out.println(i);
            }
            inputScanner.close();
                
            } catch (Exception e) {
                System.out.println("Exception");
                e.printStackTrace();
            }
        
        

    }

}


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by jure1Apr 3, 2018 08:59 AM 7 218 Apr 3, 2018 08:59 AM
Last Post: vorticalbox
[.NET] by Haters Ganna HateApr 2, 2018 03:55 PM 4 245 Apr 2, 2018 03:55 PM
Last Post: gigajew
[Python] by A!DSFeb 12, 2018 07:29 PM 0 103 Feb 12, 2018 07:29 PM
Last Post: A!DS