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

Similar Messages

  • 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

  • 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 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

  • Problem in reading from excel file with my requirement

    Hi,
    Below is my input excel file format
    A    XXX
    B    XXX
    C    XXX
    D    E   F   G  H  I    J  K  L  M  N
    XX   XX  XX  XX.........................XX
    All the A...N are headings and XX's are values.
    How should I define an internal table for this requirement. I am using FM TEXT_CONVERT_XLS_TO_SAP to read input file.
    Please let me know the correct way to define internal table for the above file format.
    Regards,
    Cheritha

    Hello Cheritha,
    Your final internal table(t_final) should have all the fields viz. A, B, C, D etc.
    You need to read the file to an internal table say t_data. In the internal table t_data, the field values will be each row in this internal table.
    So you need to loop on t_data and based on the field name assign it to the corresponding field in the internal table t_final.
    Hope this is clear if any clarification please do reply
    Regards
    Farzan

  • 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();

  • Problems with prints from RAW files

    I wonder if someone could shed some light on this problem. I uploaded some photos to Kodak through iPhoto, some were JPEG's from my old Canon Powershot and some were RAW files from my new Nikon D40. The images on my monitor from the RAW files from the D40 were great with very vivid colors and I was looking forward to my first prints from the D40. When I received the prints the photos from the old Power shot looked good but the D40 looked terrible. The prints were all washed out and very dull, the strange thing was that there was one photo that was taken with the D40 which was edited and that came out as a good print and seemed to be a JPEG. I guess its something to do with the upload of RAW files, should I be shooting in JPEG ?. I thought that iPhoto uploaded JPEG's
    Thank you in advance

    Printed RAW files will always look unsaturated or "dull" until processed and saved as a jpeg or tiff files. Think of RAW/NEF as a means of preserving ALL the available information to later "develop" a final image to be saved as tiff or jpeg for publication. Shooting in Large Fine JPEG mode will yield great results for print and web publishing, and also leave more room on your memory card and computer drive to make more great photos
    Nikon D70 & D200; TiBook 1Ghz; MacBook 2Ghz; Dual 1.8Ghz PowerMac G5; 20" Cinema Display   Mac OS X (10.3.9)   additional 300 GB internal; 160GB and 300GB externals; 10GB, 40GB, 60GB iPods

  • Problems with reading a pdf-file using Safari/Adobe Acrobat Pro

    Using Adobe Acrobat Pro 9.5.5. and Safari in Snow Leopard I open the pdf-file of  http://dare.uva.nl/document/505726 and small boxes appear in the text f.i. on page 70, 74, on the last page etc.
    I don't know why those small boxes appear only on my MacBook Pro with the installed software and others don't read a corrupt text. If I click in den pdf-file on the right side of the mouse and choose "open with Adobe Acrobat Pro" the pdf-file opens correctly (without small boxes)!

    As you discovered, Adobe Acrobat/Pro/Reader v.9 will crash for all managed user accounts that store their home folders on the server because it has "difficulty" reading and writing to a folder across a network, which is why it crashes shortly after it launches.
    HOWEVER, there is hope. All you need to do is tell Adobe to write all of its files to the local drive rather than the home folder on the sharepoint, as follows:
    While logged into your network-user account:
    1. Go to the "Shared" folder on the local drive. (Local HD > Users > Shared)
    2. Create a new folder named "9.0_x86" if you have an Intel or "9.0_ppc" if you have a PPC (without the quotes for either case). You will have to authenticate as an Administrator.
    3. Go to the Acrobat folder within the user's Application Support and delete the folder in it.
    (Home > Library > Application Support > Adobe > Acrobat > 9.0_x86 or 9.0_ppc)
    4. Open/launch the Terminal application found within the Utilities folder on you Mac.
    (Applications > Utilities > Terminal.app)
    5. In Terminal, enter the 1st command for Intel or the 2nd for PPC:
    ln -s /Users/Shared/9.0_x86 ~/Library/Application \Support/Adobe/Acrobat/9.0_x86
    OR
    ln -s /Users/Shared/9.0_ppc ~/Library/Application \Support/Adobe/Acrobat/9.0_ppc
    Adobe Acrobat 9 should now work properly. You may get the "quit unexpectedly" error message the first time you quit the application, but should only happen the one time.
    On a side note, the print spool is slow when printing very large multi-paged PDFs.
    This is a fix I found in 2009 by Dennis, can't remember where though.
    Message was edited by: Gabriel Prime

  • Read from text file takes very long after the first time

    Dear LabVIEW experts,
    I'm having a problem with read from text file. I'm trying to read only every nth line of a file for a preview with this sub vi:
    I seems to work well the first time I do it. The loop takes almost no time to execute an iteration.
    Then when I load the same file again with exactly the same settings one iteration takes around 50ms.
    Subsequent attempts seem to always take the longer execution time.
    Only when I restart the calling vi it will be quick for one file.
    When executing the sub vi alone it is always quick, but I don't see how the main vi (too complex to post here) could obstruct the execution of the sub vi.
    I don't have a the file opened elsewhere in the main vi, I don't use too much memory...
    Right now I don't now where to look. Does anyone have an idea?
    Regards
    Florian
    Solved!
    Go to Solution.

    I don't know the LabVIEW internals here, but I would think that it is quite possible that closing a file opened for read/write access writes a new copy of the file to disk, or at least checks the file in order to make sure a new file does not have to be written.
    Therefore, if your main VI calls this subVI sequentially (you don't give any information about the place of this subVI in the main VI), you are actually looking at a close (check/write) -> open operation for any time you call it, as opposed to a simple open operation the first time. If you were to open the file for simple read access (since that's all you do), it should work fast every time because there is no need to check to see if it has changed.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • Problem with reading special char from file

    Hello Oracle community,
    Got a problem when reading from a file. I am using a croatian keyboard and trying to read special charachters (ČĆŽŠĐ) from a file.
    declare
      l_file utl_file.file_type;
      s varchar2(200);
    begin
      l_file := utl_file.fopen('test_dir', 'test.txt', 'R');
      loop
        utl_file.get_line(l_file, s);
        dbms_output.put_line(s);
      end loop;
    exception
      when no_data_found then
        utl_file.fclose(l_file);
    end;But I keep getting this in dbms_output: ČƎŠĐ. For some reason it keeps skipping 2 chars Š and Ž. If I try to insert or update data the values are show correctly. What could be the cause of such a problem?
    Best regards,
    Igor

    Hi Igor,
    Looks like a NLS_LANGUAGE issue. Check the following threads:
    UTL_FILE and NLS_LANG setting
    Re: Arabic characters not displaying in Forms
    Regards,
    Sujoy

  • Read from spreadsheet file

    Hi! I am a beginner labview user and I have a problem reading data from a
    ..xls file. I have written in columns the data that i want to present in a
    waveform graph through labview. I give the path to the Read From Spreadsheet
    File tool and i connect a true constant in the "transpose" terminal. The Run
    button shows me no error but all I get in my waveform graph is a x-axis
    line. Could someone help me? Thanx

    You say that you want to read data from a .xls file. You use Read From Spreadsheet File to get the data into LV.
    You have mixed some things. A .xls file is NOT a spreadsheet file. It is a file which could be read by MS Excel and some other tools which have import filters for this file. Read from Spreadsheet File is not such a filter.
    A spreadsheet file in the context of LV is a text file where the cells of a row are separeted by a tab and the rows are separated by a end of line.
    A save thing is use Active-X automation to communicate with MS Excel. Let it load the file and read out the cells. The are examples in LV help and in the dev zone. You must have installed and licenced MS Ecxel on your target machine. Maybe someone has written such a fil
    ter for LV but I don't know it.
    The other way will only work if you use US local settings and the data is in one worksheet. Save the file with the extention .txt. So Excel will generate a text file of the correct format. Excel will use the regional settings of your machine. You can read in this file with Read From Spreadsheet File. Unfortunatly this will use fixed settings which are the same as for US regional settings.
    Waldemar
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions

  • Problem with READ DATASET when reading file from app server

    Hi,
    wondering if anyone can help, I'm using the following code to read from a file on app server, the file is of type .rtf
    OPEN DATASET file_rtf FOR INPUT IN TEXT MODE
                                 ENCODING DEFAULT
                                 WITH SMART LINEFEED.
    DO.
    READ DATASET file_rtf INTO string.
    IF SY-SUBRC = 0.
    EXIT.
    ENDIF.
    ENDDO.
    the open dataset part works sy-subrc = 0, but the read returns sy-subrc = 8 and no data is passed to string.
    Any ideas as to what is causing this problem appreciated, <removed>
    Thanks
    Edited by: Thomas Zloch on Mar 17, 2010 3:57 PM - please don't offer p...

    Hi Adam,
    The source code in the below link has details about how to read/write to application server.
    [Application server file operartions|http://www.divulgesap.com/blog.php?p=NDk=]
    Please let us know if you have any issues.
    Regards,
    Ravi

  • Help! Problem with reading objects from file

    I wrote a "Library" program for an assignment, and one of the requirements is that the library store all of its information to file upon exit, and reload this information from file when run.
    Well, the writing to file part is working. I'm using a FileOutputStream object and an ObjectOutputStream object. I can tell from the file size of the .dat file that information is going into it.
    But what I can't do is read from file. For that, I'm using a FileInputStream and an ObjectInputStream. I keep getting this exception:
    java.io.EOFException
         at java.io.DataInputStream.readInt(Unknown Source)
         at java.io.ObjectInputStream$BlockDataInputStream.readInt(Unknown Source)
         at java.io.ObjectInputStream.readInt(Unknown Source)
         at Library.readDataFromFile(Library.java:350)
         at Library.<init>(Library.java:63)
         at LibraryDriver.main(LibraryDriver.java:6)I looked this exception up and it says it's thrown when a data input stream unexpectedly ends....But I am instantiating the input streams just before I try to read from file:
                            fileInStream = new FileInputStream(libraryFile);
                   objInStream = new ObjectInputStream(fileInStream);
                   Object[] objectArray = new Object[objInStream.readInt()];Both input streams have methods that "return the number of bytes that can be read from this file input stream without blocking". Just for kicks, I tried writing that number to the console.
    For the FileInputStream, I get 404 bytes.
    For the ObjectInputStream, I get 0 bytes.
    So I guess it's a problem with the ObjectInputStream? Anyone have any suggestions as to how I can fix this, please?

    Yep, here's the relevant code from the writeToFile() method:
                          for (int i = 0; i < libraryAuthors.length; i++) {
                        currentAlphaAuthorList = libraryAuthors;
                        for (int j = 0; j < currentAlphaAuthorList.size(); j++) {
                             currentAuthor = (Author) currentAlphaAuthorList.get(j);
                             objOutStream.writeObject(currentAuthor);
                   objOutStream.flush();
                   objOutStream.close();

  • Problem with reading String from Xlsx file.

    Hi! I am trying to read string and numerical data from an xlsx file and trying to display its contents in a word file. I tried converting it to a .lvm file too. On using the "Read From Spreadsheet" tool, I get random characters as output. On using " Read From Measurement File" tool, I am getting an error saying "Error 100 occurred at Read From Measurement File->Untitled 1". What do I do? At the end I need to display the output, row by row, in a Microsoft Word file. I am so lost. Please Help.
    Solved!
    Go to Solution.

    bsvare wrote:
    labview currently does not read directly from an xlsx file. If you convert the xlsx to an xls file first, then you can use the read from spreadsheet tool to load the data from the file.
    Hey, I tried doing that. It still just gave the values 0.00 in all the cells of the indicator array. Plus my file has string in it also. The data type in the spreadsheet was "general". Here in the tool, it is "Double". I changed the tool data type to string and spreadsheet to text but I only got gibbrish for my efforts.
    Thanks anyway!

Maybe you are looking for

  • Dynamically change the value of a select list in form based on a table

    Hi Friends, I am using a form based on a table. I want to display two fields as select lists instead of text boxes and when a value in a select list is selected, the corresponding values will be listed in the next select list. For example if departme

  • Problem with Dataguarg   ORA-01102: cannot mount database in EXCLUSIVE mode

    Hi, I'm trying to create a physical standby database on my Oracle9i DB runing on WinXP. Note: I have both Primary and Standby on the same system. Actually everything went well .... I did created the standby DB but the problem is I can not start my pr

  • Java on my computer

    Im having trouble trying to get this java programming program to work. It says you need a recent JDK version installed? If anyone know please help!!!!!!

  • Internal Messages To Different Users

    HI !!! I Need to send an internal message to different users when i save an order in the standard transaction VA01, i already have the userexit, I only needs the part of the message, somebody can help me? Thanks & Regards

  • Migrate oracle database to Amazon web services

    Has anyone migrated an existing oracle database 11g or higher to the AWS  Amazon web services ? I don't believe we can use AWS's RDS Oracle service so we would have to customize it. We are presently on a linux server and use Oracle Flexible Arch.  Ho