The Artima Developer Community
Sponsored Link

Java Answers Forum
Searching / Reading a txt file...!!

1 reply on 1 page. Most recent reply: Oct 22, 2003 6:38 PM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
iqy

Posts: 1
Nickname: iqy
Registered: Oct, 2003

Searching / Reading a txt file...!! Posted: Oct 22, 2003 10:11 AM
Reply to this message Reply
Advertisement
Hi,

I'm slightly stuck on this problem. I want to search for a particular value, and once it has been found in the txt file, then i would like the whole line in which the value is located to be printed out. The values are stored as follows:

[12, 14]
[56, 89]
etc

Here is what i've been able to do so far (with struggle) and it still isn't perfect!

import java.io.*;
class read2
{
public static void main(String [] args) throws IOException
{
BufferedReader in =new BufferedReader(new FileReader("arrayStrng.txt"));

boolean found = false;
int t=in.read();
System.out.println("enter value:");
String s = in.readLine();
int x=Integer.parseInt(s);
while(t!=-1)

for(int i=1;(!found); i++)
{
in.readLine();

if (t== 's')System.out.println(//then display the whole line in which this value is);
found = true;
}
}
}

I think I'm on the right lines, but I just can't find the value from the file and print its partnering value (the remaining part of the line).

I would appreciate any help....
Thanks....Iqy


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Searching / Reading a txt file...!! Posted: Oct 22, 2003 6:38 PM
Reply to this message Reply
Why dont you check out the matches(String regex) in the String class to match the value.

Flat View: This topic has 1 reply on 1 page
Topic: String problem Previous Topic   Next Topic Topic: How to make program eat less memory/enhance performance ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use