• Post Reply Bookmark Topic Watch Topic
  • New Topic

get me out of thissssssssss

 
surya_java
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys i am workin on this code for 2 days but i was not able to succed due to lak of my experience. so pls help me out.
the code is
import javan.io.*; //a generated package purpose is explained below.
import java.io.*;

public class bufferedInput{
public bufferedInput(){
int count;
try{
BufferedInputString in = new BufferedInputString(new FileInputStream("/home/surya/data/WAMMAP2009120900.vtk"));
System.out.println("before while");
boolean EOF = false;
count=0;
System.out.println("just before while");
while(!EOF)
{
// System.out.println("workin");
if(count==1){
char c;
c=in.readChar();

System.out.println(c);
break;
}
count++;
}
in.close();
}
catch(FileNotFoundException e){
System.out.println(e);
} catch(IOException e){
System.out.println(e);
}
}
public static void main(String args[]){
new bufferedInput();
}
}
when i run this code it is givin me
before while
just before while
?
the explanation of BufferedInputString class in javan.io is explained as follows :-
Description: *
* This class is intended to speed up file *
* access time. This class works by reading *
* the file or part of the file into a byte *
* array and converted into a String. Then *
* the information (int, long, float, double, *
* and String) is retrieved from the String *
* through tokens. *
* The concept is that it is faster and more *
* effeicent to have one file access and then *
* process a byte array. Accessing the file *
* time and time again can be costly. *
* *
* This class is constructed just like *
* DataInputStream. **********************************
surya (:confused


 
Bryan Fagan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
surya_java:
What exactly are you trying to do? I wrote a class close to what you have except that I use the BufferInputStream instead of the BufferedInputString, which I don't have.
Here is the output I get:
before while
just before while
T
"T" is the first character in my test file.
Are you trying to print out only the first char in your file?
count = 0;
while( !EOF )
{
if( count == 1 )
{
char c;
c=in.readChar();
System.out.println( c );
break;
}
count++;
}
According to this code:
count is set to 0
while your file is not at the end of the file and count is 1
print out the char and break out of the loop, finally close the bufferinputstring.
As far as I can tell, if you only want to print out the first char in your file and exit, the program seems to work.
Bryan
 
surya_java
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks bryan!!!
I am actually testing to trace a file for loading the values according to a particular heading. i mean the file which i mentioned in my code has dimensions , spacing, angular directions , which r to be taken into 3 different variables and r to be plotted on a grid. i was just experimenting to trace the file so that i can do as i said before. is there any other efficient method for loading into 3 different variables ?. can i any way use string tokenizer?. pls reply me . thanks a lot in advance.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!