How to set a Buffered Reader equal to another?

Just as i,j do in this example:
for (int i=0; i<num; i++)
    {for (int j=i; j<num; j++)
    }I have 2 BufferedReader, cycling through a file:try {
BufferedReader reader1 = new BufferedReader (new FileReader (fname)) ;
BufferedReader reader2 = new BufferedReader (new FileReader (fname)) ;
while (reader1.ready()) {
   // >>> here reader2 should be where is reader1 ???
   p=Integer.parseInt(reader1.readLine());
   while (reader2.ready()) {
     q=Integer.parseInt(reader2.readLine());
     println(p+q);
}How can I reset reader2 to point to where reader1 is (at the start of each loop) ?

I guess the only way is to reset reader2 to the start of the file, and readLine until it reach reader1.
It will be somewhat wasteful, but it will work.
try {
BufferedReader reader1 = new BufferedReader (new FileReader (fname)) ;
while (reader1.ready()) {
   p=Integer.parseInt(reader1.readLine());
   BufferedReader reader2 = new BufferedReader (new FileReader (fname)) ;
   //to.be.added.here>> repeat reader2.readLine() until it reach reader1
   while (reader2.ready()) {
     q=Integer.parseInt(reader2.readLine());
     println(p+q);
}

Similar Messages

  • Jaxrpc client  (how to set connection and read time out)

    I have a jaxrpc client using a web service. how to set a connection or a readtime out on the client side so that I can terminatate the service if it does not respond on some time.

    SteveHibox wrote:
    When we tried to send messages to [email protected] ,the debug log on MTA shows that if the first mail server(123.1.1.1) failed , the MTA tried to connect the second server(123.1.1.2) automatically. And it took about 3 minutes until the connection to the first server timed out.
    The OS level timeout (tcp_ip_abort_cinterval on Solaris) is applicable to this situation. It is set to "180000" (3 minutes) by default e.g.
    bash-3.00# ndd -get /dev/tcp tcp_ip_abort_cinterval
    180000
    Is there any way to shorten the default time out ?( I mean to connect the second server faster if the first one failed.)Try changing the OS level parameter.
    If there is only a particular IP address causing the problem, you may want to make use the IP_ACCESS mapping table and the $I flag to skip over this IP address:
    http://docs.sun.com/app/docs/doc/819-4428/gekyh?a=view
    Regards,
    Shane.

  • How to set default RSS reader...

    Hi,
      how do I set an alternative default rss reader in ML ? I've NetNewsWire installed but when I select a feed:// bookmark in Safari it still goes to the default mailer (Thunderbird) in my case. How can I make NetNewsWire the detault reader?
    Cheers, Fons.

    I found and used http://www.rubicode.com/Software/Bundles.html#RCDefaultApp to set NetNewsWire as the default RSS reader. All fine now.
    Cheers, Fons.

  • Newbie How to Set a text box equal to a phrase

    I have on a page process
    begin
    if something<0 then
    :P28_DIFFMSG := 'Pkgs needed.';
    else
    :P28_DIFFMSG := 'Left over pkgs.';
    end if;
    end;
    P28_DIFFMSG is a textbox of 30 characters.
    When I run it I always get:
    ORA-01008: not all variables bound.
    I've tried using v('P28_DIFFMSG') := 'Pkgs needed';
    :P28_DIFFMSG := to_char('Pkgs needed');
    no luck.
    Suggestions?
    TIA
    Steve

    I have just tried something simpler, which is to set the value of a text box named P34_X and the source in the process is just the following one line
    :P34_X := 'trouble';
    This proves your assignment syntax is correct and it worked for me as various forms of Page Rendering Processes (Before Regions, Before Header etc).
    Perhaps you need to look at the if statement - exactly what type of thing is the 'something' you are testing in if something<0 ??

  • How to make form as read only when another time as  user sees it..

    Hi All,
    I have a form to raise the issue. once the issue is raised it appears in the issue raised reports( that is form on a report )
    so all can view this report and click on issue no ..the form with details appear .
    but i want to restrict it , by allowing only one up manager to view the form on a report in editable format rest all can just view it .
    how can i do this?????????
    can any one help me with this ????..
    my approach is like this ...
    a column called "checked shud be added to issue table , then its values must be set to "raised" when issue is submitted for the very first time..( so it is zero when the end user is submitting it ).
    when ( the logged in user =1 up manager or checked!="raised") then
    form fields to be displayed as edited
    else
    form fields need to be read only .
    Thanks & Regards,
    Nandini Thakur.
    Edited by: Nandini thakur on Jun 26, 2010 12:04 PM

    Nandini,
    If you edit any item, you can see a section where you can specify "Read-Only" condition. Here you can write your read-only logic using SQL OR PL/SQL or predefined conditions.
    Cheers,
    Hari

  • How to set field checkbox values based on another field

    I'm trying to provide the user with the ability to check one box "Check All" which would then set the check boxes for a section to the same value as shown in the example.  Anyone know how I can accomplish this?
    Thank you.
    Example
    General Category A     [  ] Check All
         [  ]  Item 1
         [  ]  Item 2
         [  ]  Item 3
         [  ]  Item 4
    If user selects "Check All", all the Items in the list for "General Category A" are then checked automatically.

    You can create a document level function to check a series of check fiels as long as they all have the same checked value.
    // document level function that can be used for many sections
    function CheckAll(aFields, sChecked) {
    // test to see Check All box for being checked
    // and if checked set to aFields to checked value
    // otherwise clear fields
    if(this.getField(event.target.name).value == 'Off') {
    // field unchecked
    this.resetForm(aFields); // clear the fields
    // end box not checked
    } else {
    // check all box has been checked
    // loop through the fields to check
    for (i = 0; i < aFields.length; i++) {
    // all fields are assumed to have a value of 'Yes' when selected
    var f = this.getField(aFields[i]); // get field for element i
    f.value = sChecked; // set to checked value
    } // end loop to check
    // end checked
    } // end unchecked
    } // end CheckAll function
    // end document level function
    You can then add a mouse up aciton for the check all check box:
    // mouse up action for check all check box
    // define array of check box fields to process
    var aSecFields = new Array('Item 1', 'Item 2', 'Item 3', 'Item 4');
    // call CheckAll function
    // passing the array list of field names and checked value
    CheckAll(aSecFields, 'Yes');
    or you can use 1 line of executable code:
    // mouse up action for check all check box
    // call CheckAll function
    // passing the array list of field names and checked value
    CheckAll(['Item 1', 'Item 2', 'Item 3', 'Item 4'], 'Yes');

  • [iPhone 2.x] How to set text of a label from another classfile?

    I've a iPhone application (tabbar application) with some UIViewControllers. Per UIViewController i've created another .xib file.
    In one of the .xib files, i've created an UIView with an UILabel and created an outlet called "lblStatus" and connected it to the UILabel. I did all with Interface Builder.
    When i execute the application everything works great.
    Now i want to change the text of UILabel (lblStatus) from another class other then the class i've defined the outlet.
    MainWindow.xib
    - UITabBarController
    - UITabBar
    - UIViewController (viewController)
    - UIViewController (redirect to photosView.xib)
    photosView.xib
    - UIView (photosView)
    - UILabel (lblStatus)
    As you can see i've the classfile viewController (.h/.m). In that file i've the method called "viewDidLoad". I'm trying to set the text of lblStatus (defined in the classfile photosView (.h/.h) from this method.
    I've tried a lot but nothing works till now, how can i fix this?
    Thanks

    I believe the best way would be to setup a weak reference to the object.
    Check out "Object Ownership and Disposal" in "Memory Management Programming Guide for Cocoa":
    http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt. pdf

  • How to set Value from 1 frame to another ?

    I am having 2 Frame. Frame A and Frame B. Frame A is having a text Field and a button. When i click on the button on the Frame A, how can p*** the value inside the text field of Frame A into a text Field of Frame B which already prepared. Please help !

    Hi,
    Use a hidden field and assign the value to this field rather than a variable so that the value could be retained on the page submission and in the AM assign the value to the DB where ever you need it and ignore the value from the actual field, Hope it helps!
    Regards,
    Yuvaraj

  • How to set a field as mandatory when another field contains specific values

    Hi SAP Experts,
    Is it possible to set the Plant Specific Material Status field as mandatory when the DChain-spec. status field contains a specific set of values? Thanks.
    Regards,
    Kim Yong

    Hi Kim,
        I think you can achieve this using the validation tab in the field.Add a new rule for validation select the condition as test and in the value you have use formula according to your senario.Select the 'Stop execution'.This will make the field mandatory.
    I hope this helps...
    Naga

  • Set an object equal to another (ie Panel = Panel)

    It is kind of hard for me to subject this out. What I am trying to do is to set an object o equal to another object, but within components.
    panelComponents.mxml
    <mx:Panel ...>
    <mx:Script>
          <![CDATA[
                           public var op:otherPanelComponents;
                         public function init():void{
                                    this = op;
          ]]>
    </mx:Panel>
    otherPanelComponent.mxml
    <mx:Panel ...>
    //do stuff
    </mx:Panel>
    So, my programming logic tells me that since both of these are objects and they are panels, they can be equal to each other. How do I do this?
    I hope it was clear.

    It is kind of hard for me to subject this out. What I am trying to do is to set an object o equal to another object, but within components.
    panelComponents.mxml
    <mx:Panel ...>
    <mx:Script>
          <![CDATA[
                           public var op:otherPanelComponents;
                         public function init():void{
                                    this = op;
          ]]>
    </mx:Panel>
    otherPanelComponent.mxml
    <mx:Panel ...>
    //do stuff
    </mx:Panel>
    So, my programming logic tells me that since both of these are objects and they are panels, they can be equal to each other. How do I do this?
    I hope it was clear.

  • How to set Auto Portrait/Landscape as default

    Hello all,
    My organization uses Adobe Reader 10.1.2. I am trying to figure out how to set up Adobe Reader to automatically select "Auto portrait/landscape" option in the printing screen when an item is printed from within Adobe Reader.
    As of now, when I go to Print a file, it automatically selects "Portrait" (or whatever the default orientation is for the default printer).  I would like for "Auto portrait/landscape" to come up as the default selected option when printing.
    Can anyone help with this? Thank you in advance!

    Hi,
    Thanks for trying to help me out with this. To answer your question, yes I have checked the properties of my printer driver. The default printer is set to Portrait. When I try to print through Adobe Reader, the printing is automatically set to Portrait. which makes sense, except that I want it to be set to Auto Portrait/Landscape.
    On some computers, Adobe Reader printing window is set to Auto Portrait/Landscape by default, so I know it can be done, but on others it is set to Portrait (the default option of the default printer). I am trying to find out why some computers are set to the Auto Portrait/Landscape option by default when printing in Adobe, while others are set to the default printer option.
    All computers have Portrait as default in their default printer properties.

  • Buffered reader need help

    Hello!
    I'm useless at java and am trying to complete a piece of code i just don't get!
    I'm reading in a text file and don't know how to complete the buffered reader section of it can anyone help!
    p
    the code is as follows.
    // Author:
    // Date:
    // The creation of the League class
    // saved as League.java to hold and manipulate icehockey team data
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    class League
    private static Team teams[]=new Team[6];
    League()
    String tName;
    String tNickname;
    String nPlayed;
    String nWon;
    String nLost;
    String nDrawn;
    try
    FileReader fr=new FileReader("Results.txt");
    //got the following syntax from p436
    BufferedReader br=new BufferedReader(fr);
    //confused!!!!     
    int i=0;
    while()
    // dunno if this is right!
    StringTokenizer st = new StringTokenizer(fr);
    while (st.hasMoreTokens())
    //will this work?
    tName=inputStream.sval;inputStream.nextToken();
    tNickname=inputStream.sval;inputStream.nextToken();
    nPlayed=(int)inputStream.nval;inputStream.nextToken();
    nWon=(int)inputStream.nval;inputStream.nextToken();
    nLost=(int)inputStream.nval;inputStream.nextToken();
    nDrawn=(int)inputStream.nval;inputStream.nextToken();
    //whats this bit about? new team instance to be written!
    //teams=;
    i++;
    fr.close();
    br.close();
    //catch exception thing wrote this dunno if it works or not
    catch (Exception e)
    if (e instanceof FileNotFoundException)
    system.out.println("Filename"+Results.txt+"not found")
         //     public int getSize()
                   //to be written
         //     public Team getTeam(int i)               
                   //to be written

    try somethign along these lines...
        try {
            BufferedReader in = new BufferedReader(new FileReader("infilename"));
            String str;
            while ((str = in.readLine()) != null) {
                process(str);
            in.close();
        } catch (IOException e) {
        }

  • I don't know how to set up my voicemail

    I Have had my iPhone 5s for several months. I have YET to be able to access/set up my voicemail. Every time I go to my voicemail, it says to press * if I have a mailbox on this system or to enter somone's 10 digit phone number to leave a message. I have tried accessing my voicemail but pressing * and entering my phone number. It then says that my mailbox is invalid. How do I set up my voicemail? I have voicemail messages stacking up.

    Voice mail is a carrier service. I suggest you contact them on how to set it up.

  • How to set item #2 in a JCombobox as selected default ?

    JCombobox always set item #1 as default.
    How to set item #2 or #3 or another # (except #1) as selected default ?

    hey,
    there is a method called setSelectedIndex(int index)
    pass the index which u want to get selected by default.
    Call this method after loading the data to the comboBox
    for ex cbo.setSelectedIndex(1);
    Hope this helps
    Nagaraj

  • How get output generated as csv file  by reading  by buffered reader and wr

    how get output generated as csv file by reading by buffered reader and writer

    String file_location = "C\temp\csv.txt");
    try {
         URL fileURL = getClass().getResource(file_location);
         if (fileURL != null){
              BufferedReader br = new BufferedReader(new InputStreamReader(fileURL.openStream()));
              String s = br.readLine();
              while (s != null)  {
                   if (!s.equals ("")) {
                        System.out.println(s);
                   s = br.readLine();
              br.close();
         else {
              // error
    catch (IOException ex){ex.printStackTrace();}rykk
    Message was edited by: a dummy
    rykk.

Maybe you are looking for

  • How to delete Infoset Query in R/3

    Hi  Gurus, I created a Infoset using SQ02 in R/3 and generated the query. Now I need to delete that Infoset query. Please advice me how to delete infoset query from the functional group in R/3. Thanks Liza

  • Now I just need an internet connection

    Last night, after trying out Linux with Ubuntu, I loaded Arch Voodoo base. The installation went very smoothly (my compliments), except that like some others I was slowed down during the install, and am now when I boot, by the following: ata2.00: ATA

  • How to make a good picture/video movie

    i have a camera that has taken 4000x3000 pictures and 1280x720 HD videosand want to make a HD DVD movie i wanted to use premiere pro for making this movie because ive become slightly used to it i am using this on a 1600x900 17-inch laptop but i cant

  • AVCHD import crash on my mac mini, works on my mac pro...

    Hi there, I got a brand new camcorder from Canon (HF11), that records movies in AVCHD (1920x1080i - 50 ips - 24 Mb/s). When I connect it to my mac pro 2008 (intel Xeon quad core), the import work flawlessly, I can edit the rush in iMovie 09 and work

  • Is there a real full list of shortcuts cs6 and cc?

    Hi is there a real full list of shortcuts for cs6 and cc? i google a lot and i found many pdf and webpage but they don't include all the shortcuts for example like to enable airbrush shift+alt+p or reselect  ctrl+shift+d thanks