Read until eof

Hi I want to read from a file certain records with certain length, each record is 100 bytes far from the other: My problems is shown within the code:
public void read(String f){
          try{
               BufferedReader br =
                    new BufferedReader( new FileReader(f));
               StringBuffer sbuf = new StringBuffer();
               String line;
               String s="";
               while( (line = br.readLine()) != null )
                  sbuf.append( line + '\n' );
               br.close();
               char [] myFileAsChars = sbuf.toString().toCharArray();
               char ch;
// = myFileAsChars[0];
               while(?????){//HERE: how to say read util the end of the file-- text file!
                    int k=16+4;
                    int comp=100;
                    for(; k<=comp; k++){
                    ch = myFileAsChars[k];
                    if(ch==00){
                         break;}
                    System.out.print(ch);
                    s += myFileAsChars[k];}
               k=(16+4)+100;//HERE: the updates that I want in my loop do not work
               comp=comp+100;}
          }catch(IOException e){}
          

You have already closed the reader
br.close(); // you closed it here
while(?????){ // this loop will be skipped

Similar Messages

  • Bash scripting: until eof

    hey guys, i was hoping for some help. i need to make a script that will constantly add read numbers together until ctrl-d (end of file) is sent. i've got the basic adding part done, but i can't get the until eof part to work, as i have no idea what the eof character is.
    here's what i've got:
    #!/bin/bash
    a=0
    until >> eof #this line doesn't work :(
    do
    read b
    a=$(($b+$a))
    echo "new number is $a"
    done
    it's the until >> eof line that i baisically made up because i don't know what it is i need there.
    any suggestions?

    rson451 wrote:Interestingly enough, I had to fix some broken shit at work today because of this.  Some old scripts were using #!/bin/sh, but using bashisms.  The scripts were moved over to a ubuntu server which has /bin/sh -> /bin/dash and hence were no longer working.
    You probably know the quote that it's easier to port a shell than a script, so I'm wandering, how did you fix the situation - installed bash & symlinked?

  • Find a word and read until a character found

    Hi,
    I am trying to find a keyword in the string and read until a character is found. Given that the keyword is available in the string several times, so all found keywords will go into an array.
    In following example: I will look for keyword "module" and will read the sentence until a space (" ") found.
    Results:
    module=pngBasicInventory.dll
    module=pngNetComms.dll
    etc..will go into an array
    Any help please?
    date=May 29 06:56:29 severity=2 hostName=STPACCESS source=EventTransport module=pngnsagent.exe process=pngnsagent.exe pid=1888 thread=4780 tickCount=759631date=May 29 06:56:33 severity=2 hostName=STPACCESS source=BasicInventory module=pngBasicInventory.dll
    process=pngnsagent.exe pid=1888 thread=1928 tickCount=763890date=May 29 06:56:36 severity=2 hostName=STPACCESS source=pngNetworkTransport module=pngNetComms.dll process=pngnsagent.exe pid=1888 thread=1928 tickCount=766869date=May 29 06:56:36 severity=2 hostName=STPACCESS
    source=CoNetworkTransport(347) module=pngNetComms.dll process=pngnsagent.exe pid=1888 thread=1928 tickCount=766869date=May 29 06:56:36 severity=1 hostName=STPACCESS source=ConfigServer module=pngnsagent.exe process=pngnsagent.exe pid=1888 thread=1928 tickCount=766869date=May
    29 06:56:36 severity=4 hostName=STPACCESS source=ServerSettings module=pngnsagent.exe process=pngnsagent.exe pid=18 thread=1928 tickCount=766869date=May 29 06:56:36 severity=4 hostName=STPACCESS source=ScheduleEngine module=AgentScheduler.dll process=pngnsagent.exe
    pid=1888 thread=1960 tickCount=766932

    Assuming this is in a file, you can use this.
    #PowerShell V3+ approach
    $Keyword = "module"
    $Content = Get-Content .\list.txt
    [regex]::Matches($Content,"\b$Keyword\=\S+\b").value
    Or if running V2
    #PowerShell V2 approach
    $Keyword = "module"
    $Content = Get-Content .\list.txt
    [regex]::Matches($Content,"\b$Keyword\=\S+\b") | ForEach {$_.value}
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

  • Read Objects EOF

    I am trying to read object from a file into a linked list, but i keep getting a EOFException when it reaches the eof, i have tred a while loop but still the exception gets thorw, whats the best way of stoping reading once eof is read without throwing the exception?
    boolean EOF = false;
    ObjectInputStream fin = new ObjectInputStream(new FileInputStream("test.dat"));
    while(!EOF)
    Record rec = (Record) fin.readObject();
    a.add(rec); //add to linked list

    i'm not understand why you don't want to use Exception
    you still can execute you other path of code even using exception
    example
    try
    .... //do something
      try
      .... read object code here
      catch (EOFException ex)
    ... your other code
    catch (Exception anyException)
    }

  • I have a new MBAir 2013 13", and I had a MBPro 2010 13". I've installed iPhoto 9.4.3 but now iPhoto says my library (stored on an external HDD) cannot be read until I update the software because it's made with an updated iPhoto... but it IS updated!

    As the tile says, I've recently bought a MBAir 2013 13". When I installed and updated iPhoto, I wanted to use my library, stored on an external hdd, which I used until the day before on my old MBPro 2010 13", without any problems. Now iPhoto says that this library cannot be opened by my iPhoto but it has to be opened with an updated iPhoto... but I had iPhoto 9.4.3 on my MBPro and I have iPhoto 9.4.3 on my MBAir! What can I do? Thanks a lot (sorry for my english, I'm Italian)

    It's mac os format
    BTW I solved my issue! I repaired my library with the last option... and I did not lost anything thanks anyway!

  • Read until a certain point in txt file

    I need to know how to read in until a '|' how do i do this? (in a txt file)

    get your file input stream and just read char at a time until u reach the |
    while(in.readChar() != '|' ){
    // do nothing
    [\code]                                                                                                                                                                                                                                                                                   

  • Read until end of line.

    Title says all. I need a way to read from a specified character in a specified paragraph until the end of that paragraph. What i'm using now: set prefsLocation to "/Applications/Bukkiteer/server_data/server.properties"
    set prefsFile to read prefsLocation
    set monsters to character 16 of paragraph 5 of prefsFile
    set animals to character 15 of paragraph 7 of prefsFile
    set maxplayers to character 13 of paragraph 8 of prefsFile
    display dialog monsters
    display dialog animals
    I need the maxplayers to go from character 13 until the end of that paragraph/line

    The index -1 refers to the last character (note that using "characters" will result in a list)set maxplayers to text 13 thru -1 of paragraph 8 of prefsFile
    In your example, you can also get the *last word* of the paragraph, depending on the punctuationset maxplayers to last word of paragraph 8 of prefsFile

  • My test instrument is outputting a 5 line string but labview only read until the carriage return. how can I get it to read the whole string?

    I have a labview sub-VI reading the string being outputted by a pH meter.  The meter outputs a 5 line string and labview is only reading up to each lines carriage return, there-by giving me 5 separate strings is there anyway to rectify this and have the 5 line read as one string?
    NAS1
    St Petersburg FL
    Labview 2010

    Yes, LabVIEW will automatically update. What happens is that the old serial functions still exist in 7.1 and above but the code (the block diagram) has been modified to use VISA functions. Older versions of LabVIEW are fully supported in this manner. The only way you can avoid the automatic update is to have the old serial functions in an llb and your top level VI refer to these. Having any VI that was part of vi.lib in an llb is a very bad idea and the way to fix things is to remove any VIs in the llb that are part of the LabVIEW distribution.
    I don't remember how the old serial config worked and what the new version does with the VISA Configure Serial Port. Your program should only have a single serial config and you might just be able to directly replace that with the VISA configure Serial Port.

  • Problem with read() and EOF

    I'm inputting a file that has a total of 18 entries delimited by commas Ex. ( 4, 5, 200, 780, 1, 0, 0, 12, 6, 0, 129, 24, 21, 44, 133, 62, 158, 7). My problem is that on the very last entry I can't get it to stop because it's looking for a comma. I tried all sorts of things like checking for if current.read() == -1 and so on but nothing seems to trigger it. If I change the while loop to go for one more time through it gives me 7followed by infinite "?". No errors are thrown so I can't even pinpoint anything that way. All I need to do is be able to read the last set of characters after the last comma and then make it stop and this program will work the way it's supposed to. Any suggestions??
                            try {
                        BufferedReader input = new BufferedReader( new FileReader( fileField.getText() ) );
                        char current = ' ';
                        int i = 0;
                        String temp;
                        while ( i < 17 ){
                             temp = new String( "" );               
                             current = (char)input.read();
                             while( current != ',' ){
                                  if( current == ' ' ){
                                  else {
                                       System.out.print( current );
                                       temp += String.valueOf( current );
                                  current = (char)input.read();
                             System.out.println( "temp = " + temp );
                             switch( i ) {
                                  case 0:     verField.setText( temp ); break;
                                  case 1: hlenField.setText( temp ); break;
                                  case 2:     servField.setText( temp ); break;
                                  case 3: totalField.setText( temp ); break;
                                  case 4: fragIDField.setText( temp ); break;
                                  case 5: flagField.setText( temp ); break;
                                  case 6: fragOffField.setText( temp ); break;
                                  case 7: TTLField.setText( temp ); break;
                                  case 8: protocolField.setText( temp ); break;
                                  case 9: headerField.setText( temp ); break;
                                  case 10: sIP1Field.setText( temp ); break;
                                  case 11: sIP2Field.setText( temp ); break;
                                  case 12: sIP3Field.setText( temp ); break;
                                  case 13: sIP4Field.setText( temp ); break;
                                  case 14: dIP1Field.setText( temp ); break;
                                  case 15: dIP2Field.setText( temp ); break;
                                  case 16: dIP3Field.setText( temp ); break;
                                  case 17: dIP4Field.setText( temp ); break;          
                             i++;     
                   catch( FileNotFoundException f ){
                   catch( IOException f ){
                   }/

    The following should work.
        public interface Settable {
            public void setText(String s);
        private static final Settable[] FIELDS = {verField, hlenField, servField, totalField, fragIDField, flagField, fragOffField, TTLField, protocolField, headerField, sIP1Field, sIP2Field, sIP3Field, sIP4Field, dIP1Field, dIP2Field, dIP3Field, dIP4Field};
        public void code(String fileName) {
            try {
                LineNumberReader input = new LineNumberReader(new FileReader(fileName));
                // read line and split by a comma with any number of spaces on either side.
                String[] vars = input.readLine().split(" *, *");
                for(int i = 0; i < vars.length && i < FIELDS.length;i++)
                    FIELDS.setText(vars[i]);
    } catch (IOException f) {
    f.printStackTrace();

  • I cant install Adobe reader until I uninstall same.

    PLEASE HELP ASAP MY COMPUTER KEEPS FREEZING
    I receive an error message when attempting to uninstall adobe reader.
      mesage  "error 1402 could not open key

    Hello again Michael.  Well I got the "installer clean up utility" installed
    but when I attempt to run the msicuu.exe file it does indicate that only an administrator can preform this function.  I am the administrator and am signed on that way,????  '
    Any more suggestions??????
    PLEASE HELP ME!!!
    Thanks again for your help... ''

  • Exec() - G77 Fortran blocks read(*,*)  until Java closes output stream.

    This is my first post!
    I have a program in fortran using G77 from GNU. When I start the program and write to the output stream I have to close() the stream for the message to arrive at the other end. G77 seems to need Java to close the stream for the message to be sent.
    Then, the stream is forever closed and can not be re-obtained for subsequent writes.
    I do not need to close() with microsoft fortran. It works fine with a simple flush().
    My code for Microsoft is below, followed by same code for G77:
    Any ideas?
    Disciple285
    // write to stream with Microsoft Fortran
    std_out.println(message);
    std_out.flush();
    // write to stream with G77 Fortran
    std_out.println(message);
    std_out.close();

    Hi:
    The internal OJVM is not affected by your installations of any other Sun JDK on the server.
    So you can not upgrade your internal OJVM without upgrading the entire DB.
    Oracle 10g includes a JDK 1.4 runtime, 11g a 1.5 runtime and so on.
    If you can upgrade your Oracle 9.2.0.8 to a 10g release you can then compile the code, if not you should re-write the code to compile with an standard JDK 1.3 release.
    Best regards, Marcelo.

  • DVD won't be read until its end

    Hello ,
    I have a iMac G5 intel , and while trying to watch a DVD movie , it stopped about 30 minutes before the end . The disk seems clean and without any scratch.
    Trying to re-enter the DVD and select the chapter , I showed a black screen while the DVD counter continued running .
    Any advice please ?
    iMac 2Ghz Intel Core duo /2Go   Mac OS X (10.4.7)  

    I have heard of this issue from sub standard or excesivly used DVD's ie Rented movies. Also, you touched on the other cause of dirt or scratches. this is normally the only cause of this problem.
    If you have a DVD that you know there is not an issue with like a brand new one you just purchased play it and it will answer the the question for you that it is more than likely a bad DVD.
    Cheers Don

  • Two PrintWriter objects in a servlet class

    Hi-
    In one of my servlet, I have written the below code
    PrintWriter out=res.getWriter();
    +          out.write("hi");+
    +          out.close();+
    +          PrintWriter out2=res.getWriter();+
    +          out2.write("hi again");+
    +          out2.close();+
    This will print "hi" but not printing "hi again".
    Can anybody tell me what would be the reason behind this..
    Thanks in advance.

    Do you take any time to think about your questions, or do you just post them in rapid fire?
    In one of your other postings you already noted that when you close a PrintWriter it doesn't give an Exception when you try to write to it again.
    So I would guess because you've close it, you can't just open it by using the getWriter() method.
    Or your class on the other end only reads until EOF and since you've already closed it, there is nothing else to read.

  • About NIO non-blocking socket write method behavior

    Hi all -
    I hope anyone could help in this issue.
    Assume you create a NIO socket and configure its channel in non blocking mode:
    channel.configureBlocking(false);
    then you write a byte buffer into it:
    int sentBytesNum = channel.write(byteBuffer);
    What are the possibilities of sentBytesNum value? I am sure of two possibilities, which are:
    - all data sent so sentBytesNum equals byteBuffer data size (limit minus position before sending) (after sending the limit and position of byteBuffer are the same)
    - no data is sent so sentBytesNum is zero and byteBuffer limit and postion did not change, so we shall use a write selector to test when the channel will be ready for write to write the data.
    What I am not sure about and need someone to confirm is the third possibility:
    - only a part of data is sent (according to the available free space of socket output buffer) so sentBytesNum is more than zero but less than data size and byteBuffer position is advanced by the value of sentBytesNum, might this possibility happen??
    If yes, so we should manage to hold the non sent part of byteBuffer till the channel becomes ready for write (we can know that using write selector) so we can write it to channel???
    Thanks for help,
    Rocka

    Yes, case three can occur. The usual NIO write loop looks like this:
    int count = 0;
    while (buf.position() > 0)
      buf.flip();
      count = ch.write(buf);
      buf.compact();
      if (count == 0)
        break;
    }This will run until buf.position() == 0 or count == 0. If the partial write case happens it will loop one more time and probably get a 0 count.
    At the end of the loop, if buf.position() > 0 there is still unwritten data and at this point you should register for OP_WRITE and return to the selector. Otherwise if there is no data unwritten you should deregister OP_WRITE as you have nothing to write and aren't interested in the event any longer.
    If you are reading something and writing at the same time the logic goes like this:
    while (inch.read(buf) >= 0 || buf.position() > 0)
      // etc
    }This will read until EOF occurs and either buf.position() is zero or a zero length write occurred.

  • How do u do this in IO programming

    Hi
    here is a sample code. How can i make it so that the user can look for a file in windows to read the file.
    At the moment the code is set at defalt "readme.txt"
    Can you also tell me how to save the things i read to a file of the user choose.
    import java.io.* ;
    public class IO {
    public static void main( String args[] ) {
    try {
    FileReader fread = new FileReader( �readme.txt� );
    BufferedReader bufread = new BufferedReader( fread );
    String fileLine = bufread.readLine() ; // read first line
    while( fileLine != null ) {            // read until eof
    System.out.println( fileLine ) ;
    fileLine = bufread.readLine() ; // read next line
    catch( FileNotFoundException e ) {
    System.out.println( �File not found!� ) ;
    System.exit( 0 ) ;
    catch( IOException e ) {
    System.out.println( �IO Exception when reading file� ) ;
    System.exit( 0 ) ;
    }

    what i mean is how can i change my code so that it will look like windows file open command/save command.
    what i mean by that is when u click save in windows notepad or some thing it will bring up a windows showing all the contain of ur hard drive. in that window u have save and cancel button and u can browes the file from the space they have. then it got a text field for the user to type in the name of the file to save.
    All I wanted to know that is , In java swing is there any of those type of windows around that i can call up to save / open my file with

Maybe you are looking for