Problem in reading from the File

Hi,
I have a dataset.txt file which is as follows:
2
4
1 2 3 4
2 3 4 5
3 4 5 6now that I need the value that is present in the 1st line of the file(ie;2) and value present in the 2nd line of the file(ie;4), upon that i'll be reading the data into an array.
for this task of mine to accomplish , i'm using the following code
String line_1;
String line_2;
          int first_line,second_line;
          DataInputStream dis1 =null;
          DataInputStream dis2 =null;
          System.out.println("Print this");
          try
               File f1=null;
               f1 = new File ("dataset.txt");
               File f2=null;
              f2 = new File ("dataset.txt");
             FileInputStream fis1 = new FileInputStream(f1);
             FileInputStream fis2 = new FileInputStream(f2);
             dis1 = new DataInputStream(fis1);
             dis2 = new DataInputStream(fis2);
                       BufferedReader line1 = new BufferedReader(new InputStreamReader(dis1));
                  line_1=line1.readLine();
                  first_line=Integer.parseInt(line_1);
                  System.out.println("Value of First_line is:     "+first_line);
                  BufferedReader line2 = new BufferedReader(new InputStreamReader(dis2));
                  line_2=line2.readLine();
                  second_line=Integer.parseInt(line_2);
                  System.out.println("Value of Second_line is:     "+second_line);
}//end of try
catch(Exception e)
{e.printStackTrace();}The problem here I'm having is, when i'm printing I'm getting the follow result
Value of First_line is:2
Value of Second_line is:2Instead of printing the value of Second_line as 4, it is printing 2.
Why is this happening?
Any kind of response is appreciated.
Thanks is advance

You dont have to make 2 data stream objects of the file.
To read two lines you can just do with it object
BufferedReader line1 = new BufferedReader(new InputStreamReader(dis1));and just call readLine( ) method twice
line_1=line1.readLine();
line_2=line1.readLine();

Similar Messages

  • I am getting "a network error occurred while attempting to read from the file c:\windows\installer\itunes.msi" when I attempt to download itunes, can someone help me with this?

    I am getting "a network error occurred while attempting to read from the file c:\windows\installer\itunes.msi" when I attempt to install itunes.  Can anybody help me to resolve this issue?

    You can try disabling the computer's antivirus and firewall during the download the iTunes installation
    Also try posting in the iTunes forum since it is not an iPod touch problem.

  • Cannot delete itunes from pc,message states. a network error occurred while attempting to read from the file C:\windows\installer\itunes.msi

    ITUNES WILL NOT DELETE FROM ADD @ REMOVE PROGRAMS,
    MESSAGE, READS  a network error occured while attempting to read from the file  C:WINDOWS\installer\iTunes.msi

    All sorted now just needed to repair itunes from control panel

  • How to print the content in Reverse which is read from the file

    i have written a program to display the content of the file using files concept. now the task is how to display it in reverse order i.e from last to first which is read from the file.

    If it will all fit in memory read the file as you are doing now appending everything into a StringBuilder. Then use the reverse() method of that class to obtain your output.
    http://java.sun.com/javase/6/docs/api/java/lang/StringBuilder.html#reverse()

  • While updating the older version iTunes to latest one it shows "a network error occurred while attempting to read from the file: C:\windows\installer\iTunes64.msi. pls help on this matter to connect my i5 to PC. Thanks in advance

    while updating the older version iTunes to latest one it shows "a network error occurred while attempting to read from the file: C:\windows\installer\iTunes64.msi. pls help on this matter to connect my i5 to PC. Thanks in advance

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page): 
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • When I try to install Itunes, I get this error: (translated from Norwegian) There was a network error while trying to read from the file: C: \ windows \ installer \ iTunes.msi I have tried many times to reinstall, but nothing helps, please help me.

    When I try to install Itunes, I get this error: (translated from Norwegian) There was a network error while trying to read from the file: C: \ windows \ installer \ iTunes.msi I have tried many times to reinstall, but nothing helps, please help me.

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • Trying to update to iTunes 10.4.1 and I get a message "A network error occured while attempting to read from the file C:|Windows|Installer|iTunes.msi"  Running WIndows 7 with all updates done.  I  have never had an issue with iTunes updating before.  Anyo

    iTunes has tried to update itself and runs into an error and tells me to manually install.  When I d/l and run the iTunesSetup.exe file I always encounter the following error message...
    "A network error occured while attempting to read from the file C;|Windows|Installer|iTunes.msi" and iTunes does not update to iTunes 10.4.1.
    Anyone know what is creating this error message?  Thanks for the help...

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page): 
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • When reading from the file validate the date  'DD/MM/YYYY'  format

    Hi,
    reading from the file ,validate the date format 'DD/MM/YYYY'.
    Thanks & regards
    venkata

    I suppose that you are writing a program in some programming language, probably PL/SQL. So, you can use TO_DATE function and handle the exception when it occurs.
    create or replace procedure tstdt
    as
      stdt varchar(10);
      dt date;
    begin
      stdt := '20/10/2006';
      dt := to_date(stdt);
       dbms_output.put_line('date is correct
    exception
    when others then
      dbms_output.put_line('Invalid Date');
    end;[],
    Miguel

  • Problem with reading from bin file into Vector

    What am I doing wrong? It works fine to write the vector to the bin file and then read from it. But if I try just to read from the file it wont work.
    Does anybody has any good advice to give when it comes to reading data form a bin file??
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    class Binaerfil
         public static void main (String [] args) throws IOException, ClassNotFoundException{
              ObjectOutputStream utFil = new ObjectOutputStream (new FileOutputStream("HighScoreLista.bin"));
              int po = 50;
              Spelare s;
              Spelare s1, s2, s3, s4, s5,s6,s7,s8,s9,s10;
              String f�rNamn;
              Vector v = new Vector();
              s1 = new Spelare("Mario", 100);
              s2 = new Spelare("Tobias",90 );
              s3 = new Spelare("Sanja", 80 );
              s4 = new Spelare("Marko", 70 );
              s5 = new Spelare("Sofia", 60 );
              s6 = new Spelare("Kalle", 50 );
              s7 = new Spelare("Lisa", 40 );
              s8 = new Spelare("Pelle", 30 );
              s9 = new Spelare("Olle", 20 );
              s10 = new Spelare("Maria",10 );
              v.add(s1);
              v.add(s2);
              v.add(s3);
              v.add(s4);
              v.add(s5);
              v.add(s6);
              v.add(s7);
              v.add(s8);
              v.add(s9);
              v.add(s10);
              System.out.println ("Before writing to file");
              System.out.println(v);
              //Write to file
              utFil.writeObject (v);
              utFil.close();
         ObjectInputStream inFil = new ObjectInputStream (new FileInputStream("HighScoreLista.bin"));     
              v =(Vector) inFil.readObject();
         System.out.println (v);
              inFil.close();
    }

    Because what you are writing to the file is a vector, that is all you can get out. You are actually reading a single Object from the file which you can cast to a Vector, from which you can access the data stored inside. If you want to read the Spelare instances from the file, you will have to save them individually to the file. You will have to implement Serializable and look up the API to do that.

  • Problem with reading from DAT file. FileNotFound exception

    Can't seem to find the issue here. Two files, one (listOfHockeyPlayers) reads from a DAT file a list of players. The other (HockeyPlayer) has just the constructor to make a new hockey player from the read data.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.awt.*;
    import java.io.*;
    public class ImportHockeyPlayers
    private ArrayList<HockeyPlayer> listOfHockeyPlayers = new ArrayList<HockeyPlayer>();
    public ImportHockeyPlayers(String fileName)
      throws FileNotFoundException
      try
       Scanner scan = new Scanner(new File(fileName));
       while (scan.hasNext())
        //Uses all the parameters from the HockeyPlayer constructor
        String firstName = scan.next();
        String lastName = scan.next();
        int num = scan.nextInt();
        String country = scan.next();
        int dob = scan.nextInt();
        String hand = scan.next();
        int playerGoals = scan.nextInt();
        int playerAssists = scan.nextInt();
        int playerPoints = playerGoals + playerAssists;
        //listOfHockeyPlayers.add(new HockeyPlayer(scan.next(),scan.next(),scan.nextInt(),scan.next(),scan.nextInt(),scan.next(),
         //scan.nextInt(),scan.nextInt(),scan.nextInt()));
      catch(FileNotFoundException e)
       throw new FileNotFoundException("File Not Found!");
    public String toString()
      String s = "";
      for(int i = 0; i < listOfHockeyPlayers.size(); i++)
       s += listOfHockeyPlayers.get(i);
      return s;
    public class HockeyPlayer
    private String playerFirstName;
    private String playerLastName;
    private int playerNum;
    private String playerCountry;
    private int playerDOB;
    private String playerHanded;
    private int playerGoals;
    private int playerAssists;
    private int playerPoints;
    public HockeyPlayer(String firstName, String lastName, int num, String country, int DOB,
      String hand, int goals, int assists, int points)
      this.playerFirstName = firstName;
      this.playerLastName = lastName;
      this.playerNum = num;
      this.playerCountry = country;
      this.playerDOB = DOB;
      this.playerHanded = hand;
      this.playerGoals = goals;
      this.playerAssists = assists;
      this.playerPoints = goals + assists;
    DAT File
    Wayne Gretzky 99 CAN 8/13/87 R 120 222
    Joe Sakic 19 CAN 9/30/77 L 123 210These are all in early development, we seem to have the idea down but keep getting the odd FileNotFound exception when making an object of the ImportHockeyPlayers class with the parameter of the DAT file.
    We might even be on the wrong track with an easier way to do this. To give you an idea of what we want to do...read from the file and be able to pretty much plug in al lthe players into a GUI with a list of the all the players.
    Thanks for your time.

    Thanks for the tip on the date format...good to
    know.
    public static void main(String[] args)
    GUI gui = new GUI();
    ImportHockeyPlayers ihp = new
    ImportHockeyPlayers("HockeyPlayers.dat");
    }It's just being called in the main.
    Throws this error:
    GUI.java:39: unreported exception
    java.io.FileNotFoundException; must be caught or
    declared to be thrown
    ImportHockeyPlayers ihp = new
    ImportHockeyPlayers("HockeyPlayers.dat");
    ^This error is simply telling you that an exception may occur so you must enclose it in a try catch block or change the main method to throw the exception as follows
    public static void main(String[] args) throws  
                          java.io.FileNotFoundException {
         GUI gui = new GUI();
         ImportHockeyPlayers ihp = new
         ImportHockeyPlayers("HockeyPlayers.dat");
    }or
    public static void main(String[] args) {
         GUI gui = new GUI();
         try {
              ImportHockeyPlayers ihp = new
              ImportHockeyPlayers("HockeyPlayers.dat");
         catch (FileNotFoundException e) {
              System.out.println("error, file not found");
    }I would reccomend the second approch, it will be more helpful in debugging, also make sure that the capitalization of "HockeyPlayers.dat" is correct
    hope that helps

  • How to do the paging while reading from the file !!!

    I've able to display the contents of the file in my jsp as a tabular form. I want to apply the paging concept in my jsp page. As i did in my database project there i's sending the next value as a parameter and it works.
    But when i retrieving the value from the file then i'm not able to get particular values anyhow i'm using the concepts of getLineNumber() but unable to get the previous one worked. I want to diplay only the first 20 contents of the file then, by clicking the next button he should be able to view the next 20 contents of the file. Please help me out for this problem. If possible send me the codes too it'll very helpful for me.
    in advance thanks....

    I hope the following code will help u.
    If your bean is:
    public class yourBean
    private int startIndex ;
    private int pageSize ;
    private int endIndex ;
    public void useBean()
    startIndex = 0;
    pageSize = 10;
    endIndex = pageSize;
    public setters and getters for each of the above.
    In servlet :
    doGet/doPost:
    yourBean uBean =
    (yourBean)sess.getAttribute("urBean");
    int sIndex = uBean.getStartIndex();
    int eIndex = uBean.getEndIndex();
    int pSize = uBean.getPageSize();
    if (sIndex = 0)
    //means first time
    dont do anything
    if ((sIndex >0)&&(sIndex <
    uBean.getRecords().size())))
    eIndex = sIndex + pSize - 1;
    sIndex = eIndex;
    //update Indexes to the bean
    uBean.setStartIndex(sIndex);
    uBean.setEndIndex(eIndex);
    sess.setAttribute("urBean",uBean);
    res.sendRedirect("yourJSP.jsp",req,res);
    In yourJSP.jsp:
    <jsp:useBean id="urBean" type="...." scope="session"
    />
    <%
    int sIndex = urBean.getStartIndex();
    int eIndex = urBean.getEndIndex();
    for (int
    i=sIndex;(i<=eIndex)&&(i<urBean.getRecords().size()))
    out.println(....);
    if (eIndex >= urBean.getRecords().size())
    out.println("NExt");
    else
    out.println("<a href=yourServlet>Next</a>");
    if (sIndex <= 0)
    out.println("Previous");
    else
    out.println("<a href=yourServlet>Previous</a>");
    %>

  • Problem with reading from a file

    `HI,
    i am trying to read from a text file... using following piece of code
    try{               
                   BufferedReader in = new BufferedReader( new FileReader(fileName), 100000);
                   while (in.readLine() != null)
                        temp = in.readLine();
                   in.close();
                   in = null;
                   } catch(Exception e) {System.err.println(e); }          
                   System.out.println(temp);     
    text contains almost 7500 words...
    but when i run this piece of code... output i got is NULL
    ... i don't know what i am doing wrong...
    any suggestions
    <Thanx in advance >

    while (in.readLine() != null)Right here, you are reading in the file, but you don't store the content.
    temp = in.readLine();By the time you reach here, you have already read in the whole file, so there is nothing left to read. That's why temp is assigned null

  • I am trying to update iTunes but get this box message comes up, "Network error occurred while attempting to read from the file: c:/windows/installer/itunes.msi" I have be told to uninstall all iTunes then reinstall, if I do this will I lose my Library

    Looking on the net to solve this problem, it says
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    I have save all my iTunes on a CD.
    If I uninstall iTunes, will I lose my iTunes library and video and apps and inturn will I lose this off my phone..
    I have tryed to update my iPhone firmware as they said there is a new update firmware, it would not install this and put my phone into recovery mode and I had to use iPhone recovery fix to get it out of recovery mode, my iPhone did a back-up before it tried to update the firmware.
    Any idea's are welcome

    Download the Windows Installer CleanUp utility from the following page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    To install the utility, doubleclick the msicuu2.exe file you downloaded.
    Now run the utility ("Start > All Programs > Windows Install Clean Up"). In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • Problem using read from spreadsheet file and polar plotting

    Hi to all labview users,
    i am a beginner in labview and i am trying to do a polar plot.
    i read the polar plotting example in labview and it was straightforward.
    I used "write to spreadsheet file" to gather data.
    and they are in the following format
    13  10
    4  20
    8 30
    ....etc
    now. i tried using "read from spreadfile" to get the data into a array, then using "array to cluster" to convert the array into cluster, so i could connect it to the polar plot block
    however, it kept saying i couldnt connect that way, because polar plot uses 1-d array with cluster of 2 element and my source is a cluster of 9 elements....
    but doesnt the "read from spreadfile" block give me a 1-d array? and where does that 9 come from? i only have 3 rows and 2 columns in my data file....
    any guidance would be greatly appreciated.
    thx alot
    Happy guy
    ~ currently final year undergraduate in Electrical Engr. Graduating soon! Yes!
    ~ currently looking for jobs : any position related to engineering, labview, programming, tech support would be great.
    ~ humber learner of LabVIEW lvl: beginner-intermediate

    Helllo,
    I've made an example to try to help you  with that question.
    Notes:
     - the file must have values separeted by tab
     - reading the values from file as you mentioned using "read from spreadfile" you'll get a 2D array and not 1D;
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Read Table and plot polar graph.vi ‏26 KB
    teste.txt ‏1 KB

  • Problem while reading from text file using JDeveloper 10.1.2

    Hi,
    I am using JDeveloper 10.1.2 for my application. In this, I have one requirement to read some data from a text file. For that, I created a test file and saved along with the java file folder. From there, I am trying to read this file but it says the file not found exception.
    Application is looking the file from another location. "F:\DevSuiteHome_1\jdev\system10.1.2.1.0.1913\oc4j-config"
    But, I want to read it from my home folder. How is it possible to read from that location?
    Regards,
    Joby Joseph

    HI,
    Check followings will useful
    How to read .txt file from adfLib jar at model layer using relative path
    Accessing physical/relative path from Bean

Maybe you are looking for

  • Sword cut effect with falling paper

    okok the title is a bit ahrd to understand, i try to explain i want to create an effect where i use a sound of a sword that slash 3-4 times i want to make an: objector a text or something hide from a black screen by "cutting" the black screen and mak

  • CD burning problem on MacBook - What am I doing wrong?

    Hello, I've finally made the jump from PC to Mac but so far I seem to be falling over on some very basic steps! I'm trying to burn some photos onto a CD, which really should be very simple (I copied them from an external drive, not through iPhoto). I

  • Chase Southwest Rapid Rewards-APPROVED

    I found these boards so helpful in deciding whether or not I should apply, so I thought I'd share my experience for any others who may be interested in this card.  All 3 of my scores are right around 650.  I have a 4 year old car repo, and a few 6 ye

  • Usb redirection in KIOSK mode

    Dear all, i am trying to redirect usb flash disk connected to DTU to windows terminal server. i am using the script provided in the other forum http://blogs.sun.com/danielc/entry/a_usb_drive_daemon_for1 i am getting error or it is not redirecting (us

  • Automate  and  Batch actions

    I am converting tiff files to jpeg using the Automate then Batch Actions. I select my source folder and Destination folder. The program converts and send the jpegs to the Destination folder but it is also sending a copy of every jpeg to my DESKTOP. N