-
reading from file...seems to be agille
Hi,
i have a problem, well it's more a question. I shall write short prog. that will read a text file consisted of words separated with emty space. I know about tokens and I was intended to use them, but a friend of mine suggested me another option, but without any example.
He realized, that there are only 2 words that i need to know. Both are always in the first half of line. So he suggested to read the line not by words but chars and after reading what i need to jump on next line.
So he wanted to shorten somehow reading the file.
the line looks like that
servername date time numberofhits exactdirectoryopened...
Is his idea possible or should I rather use tokenizer?
-
try
{
InputStreamReader isr=new InputStreamReader(new FileInputStream(new File("Test.txt")));
char c;
int i=0;
while((i=isr.read())!=-1)
{
c=(char)i;
}
isr.close();
}
catch (IOException ioe)
{
System.err.println(ioe);
}
this will read 1 char at a time from your file until it reaches the end of the file, hopefully this will help you get what u need.
¿Red Baron?
[code] /* dont forget code tags! */ [/code]
Come visit the Café!
-
Originally posted by Red Baron
try
{
InputStreamReader isr=new InputStreamReader(new FileInputStream(new File("Test.txt")));
char c;
int i=0;
while((i=isr.read())!=-1)
{
c=(char)i;
}
isr.close();
}
catch (IOException ioe)
{
System.err.println(ioe);
}
this will read 1 char at a time from your file until it reaches the end of the file, hopefully this will help you get what u need.
thx, will try...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks