7 Replies - 1194 Views - Last Post: 29 August 2009 - 04:32 PM Rate Topic: -----

#1 idk12   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 109
  • Joined: 25-August 09

scan a text file and return value

Post icon  Posted 29 August 2009 - 10:37 AM

Hello, i need help making a program that will scan a text file and return it's value. I did some researches and found nothing helpful. Thanks

 import java.io.File;
   import java.io.FileNotFoundException;
   import java.util.Scanner;

   public class Scannercode {


that's all i know.
Is This A Good Question/Topic? 0
  • +

Replies To: scan a text file and return value

#2 aks29921   User is offline

  • D.I.C Regular

Reputation: 116
  • View blog
  • Posts: 345
  • Joined: 24-August 09

Re: scan a text file and return value

Posted 29 August 2009 - 10:52 AM

View Postidk12, on 29 Aug, 2009 - 09:37 AM, said:

Hello, i need help making a program that will scan a text file and return it's value. I did some researches and found nothing helpful. Thanks

 import java.io.File;
   import java.io.FileNotFoundException;
   import java.util.Scanner;

   public class Scannercode {


that's all i know.


clarify what u want to do & give some code to show what you have tried, after that you will be helped...
Was This Post Helpful? 0
  • +
  • -

#3 idk12   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 109
  • Joined: 25-August 09

Re: scan a text file and return value

Posted 29 August 2009 - 10:55 AM

i want to create a code that will read a text file and return what's in the text. I wish i can give you some more code but i am a complete beginner.

public static void main(String[] args) throws IOException  

File fileName = new File("test1.txt");  
Scanner inFile = new Scanner(fileName);


This post has been edited by idk12: 29 August 2009 - 10:56 AM

Was This Post Helpful? 0
  • +
  • -

#4 aks29921   User is offline

  • D.I.C Regular

Reputation: 116
  • View blog
  • Posts: 345
  • Joined: 24-August 09

Re: scan a text file and return value

Posted 29 August 2009 - 11:03 AM

View Postidk12, on 29 Aug, 2009 - 09:55 AM, said:

i want to create a code that will read a text file and return what's in the text. I wish i can give you some more code but i am a complete beginner.

public static void main(String[] args) throws IOException  

File fileName = new File("test1.txt");  
Scanner inFile = new Scanner(fileName);



in that case, i sugget u to read your book/s and search the internet....
in short, try yourself first.
it is against the policy of this site to give code lyk this........
u will be helped here when u r stuck and u hv to show us what u hv tried to do
Was This Post Helpful? 0
  • +
  • -

#5 pawan_mangal1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 03-August 09

Re: scan a text file and return value

Posted 29 August 2009 - 11:46 AM

for reading an any file first you need to open in read mode java provide many class to read content from file like
FileReader, BufferedReader, RandomAccessFile,
suppose you want to read the content of file pawan.txt then create a object of any class that mention above
FileReader fr=FileReader("pawan.txt");
BufferedReader br=BufferedReader(fr);
then read content of file by readLine() method that is provided by BufferedReader class it read one line at a time and return String. and after end of last line it return null
String str=null;
if((str=br.readLine)!=null){System.out.println(str);}
Was This Post Helpful? 0
  • +
  • -

#6 idk12   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 109
  • Joined: 25-August 09

Re: scan a text file and return value

Posted 29 August 2009 - 02:01 PM

alright, thanks

This post has been edited by idk12: 29 August 2009 - 02:06 PM

Was This Post Helpful? 0
  • +
  • -

#7 Ice(ITB)   User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 19-August 09

Re: scan a text file and return value

Posted 29 August 2009 - 02:34 PM

You don't even need to leave this site to find the answer:
check out this tutorial.... there's hundreds like it online

http://www.dreaminco...wtopic27972.htm
Was This Post Helpful? 0
  • +
  • -

#8 idk12   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 109
  • Joined: 25-August 09

Re: scan a text file and return value

Posted 29 August 2009 - 04:32 PM

how come i don't see any directory to that helloworld.txt file

This post has been edited by idk12: 29 August 2009 - 04:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1