I need some help here.
I can not figure out where to put my .txt info at.
I 'm trying to use my instructure, some what confused. I have also read the info form Java and they really don't give an example on how to use a scanner where the user is prompt to find a text file once the file is found it then will display it
here is my code so far
Expand|Select|Wrap|Line Numbers
- public class Reading{
- public static void main(String[] args) throws Exception {
- Scanner kbd = new Scanner(System.in);
- int choice;
- System.out.println("Make a Section: ");
- System.out.println("1. Read Text File ");
- System.out.println("2. Copy Text File ");
- System.out.println("3. Exit ");
- System.out.print("\nPlease press Enter afer each response");
- System.out.println("Enter your choose please: ");
- choice = kbd.nextInt();
- kbd.nextLine();
- if (choice == 1) { // if 1 is select go to makePerson
- String fname;
- FileInputStream fin;
- long datalen=0;
- Scanner kbd1 = new Scanner(System.in);
- System.out.println("Enter file name");
- fname = kbd1.next();
- kbd1.nextLine();
- fin = new FileInputStream("c:\\data.in");// not to sure how the .txt is found
- while( fin.read()!=-1) {
- datalen++;
- }
- System.out.println("File "+fname+" is "+datalen+" bytes long");
- }
- }
thanks
sandyR
PS is this code right.
Do I need to use PrintWriter or can I use Printf(fname)