help with I/0 with prompt

Hello everyone.

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 and where to plac the .txt.

here is my code so far

publicclass Reading{

publicstaticvoid 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");//

while( fin.read()!=-1){

datalen++;

}

System.out.println("File "+fname+" is "+datalen+" bytes long");

}

}

thanks

sandyR

PS is this code right.

It needs to find the .txt then open the file and display the contents. Do I need to use PrintWriter or can I use Printf(fname)

Message was edited by:

SandyRed

[2488 byte] By [SandyReda] at [2007-11-27 2:40:02]
# 1

I can't really tell what you are asking, but you can use a Scanner to read from a file.

Scanner scan = new Scanner(new File("C:\file.txt")); //catch an exception here

while(scan.hasNextLine())

{

System.out.println(scan.nextLine());

}

CaptainMorgan08a at 2007-7-12 3:02:36 > top of Java-index,Java Essentials,New To Java...
# 2
No that's not what I need. Thanks thou....What I need to do is have a scanner which prompts the user input informationThat input then looks for the .txt file. and then display it.sandyrMessage was edited by: SandyRed
SandyReda at 2007-7-12 3:02:36 > top of Java-index,Java Essentials,New To Java...
# 3
I just gave you the part that reads from a file, it looks like you already know how to read user input.
CaptainMorgan08a at 2007-7-12 3:02:36 > top of Java-index,Java Essentials,New To Java...
# 4

OK...

How or where do I place or find the .txt info.

how does the system know where to look.

("c:\\data.in") does that is data.in...what does this mean. is it a file placement ie folder or do the it look up all the files in c:

thanks

sandyr

Message was edited by:

SandyRed

SandyReda at 2007-7-12 3:02:36 > top of Java-index,Java Essentials,New To Java...