Reading from a file doesn't work...

Hi All,
I am tring to read from a file tickets.txt and when I do this
BufferedReader inFile = new BufferedReader (new FileReader("tickets.txt"));
StringTokenizer tokens = new StringTokenizer(inFile.readLine(), ":");StringTokenizer throws a null pointer exception... and I couldn't work out why... so I did this in between BufferedReader and StringToken
System.out.println(inFile);And it printed this on the screen... which is not in my file...
java.io.BufferedReader@1c78e57
Please Help,
Mike

C:\Program Files\Java Studio_JDK\s1studio\bin
is what it prints... which is not where my file is...
but it created a file there ... and I added stuff to the new file I found and it still prints null?
some of my code...
PrintWriter pw = new PrintWriter (new BufferedWriter (new FileWriter ("tickets.txt")));
BufferedReader inFile = new BufferedReader (new FileReader("tickets.txt"));
System.out.println(inFile.readLine());
BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));thats all in the main and thats all that really has anything to do with tickets.txt right now... everything else is commented out for now...once I manage to read the file then I will uncomment it...(the methods and stuff)
Thanks,
Mike

Similar Messages

  • Read From Binary File doesn´t work on MCB2400 in LV2009 Embedded ARM

    Hello,
    I try to read a Binary File from SD-Card on my MCB2400 Board with LV2009 Embedded for ARM.
    But the output is always 0, if I use my VI on the MCB2400. If use the same VI on the PC it works fine with the same binary file.
    The
    access to the SD-Card on the MCB2400 works in other cases finde, if I
    try to read from a text-file it works without any problems.
    Are thre any constraints for the "Read From Binary File"-Node in Embedded in comparison to the same node on PC ?
      I have noticed that there is also a problem
    with the reading of textfiles. If the sice of the file is about 100Byte
    it doesn´t work anymore, too. I can´t understand it, because I read
    always just one Byte. And even if the implementation in Labview is so
    bad that it allways reads the total file in the ram it sould work. The
    MCB2400 has 32MegaByte RAM, so 100Byte or even a few MegaByte should
    work.
    But this doesn´t seem to be the Problem for the Binary-Problem. Because even a 50byte Binary-File doesn´t work.
    bye & thanks
    amin
    Solved!
    Go to Solution.
    Attachments:
    SD_Card_Read-test.vi ‏12 KB

    Hello,
    thank you for your Help.
    But I just want to read a Binary File, which is build by another program. And this is coded with 8Bit (like a normal Binary File) and not just with 7Bit (ASCII). So the workaround doesn't work in my case.
    I posted the Test-VI in my first post (here once again as picture). And it works fine on the PC, but if I try it on my MCB2400 the "Read Form Binary File" Node doesn't work.
    And it is also possible to open the Bin file with the "Read Text File" Node and see the cryptic content of the Bin-File. So the Problem seems to be in the "Read Form Binary File" Node.
    bye & thanks again
    amin
    Message Edited by aminat on 09-30-2009 03:28 AM

  • Create AAC from Wav file doesn't work

    I've converted many WAV files to AAC and it worked fine.  The last few times I've tried it it isn't working.  I hear the bleep which I think indicates it's been converted but I can't find it anywhere so assume it didn't happen. 
    I have Windows XP.  I am running iTunes  10.3.1.55
    Any ideas would be appreciated.
    Thanks,
    Ginny

    Hello,
    thank you for your Help.
    But I just want to read a Binary File, which is build by another program. And this is coded with 8Bit (like a normal Binary File) and not just with 7Bit (ASCII). So the workaround doesn't work in my case.
    I posted the Test-VI in my first post (here once again as picture). And it works fine on the PC, but if I try it on my MCB2400 the "Read Form Binary File" Node doesn't work.
    And it is also possible to open the Bin file with the "Read Text File" Node and see the cryptic content of the Bin-File. So the Problem seems to be in the "Read Form Binary File" Node.
    bye & thanks again
    amin
    Message Edited by aminat on 09-30-2009 03:28 AM

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

  • Read From Measuremen​t File doesn't work

    I am using LV 8.0 and have a daq program that writes data to a .lvm file every two seconds.  When I use the Read From Measurement File block the resulting waveforms have dt set to 0 rather than 2 as it says in the file.  All the y values are good but I have to ue the Build Waveform function to set dt to 2 but I should not have to do that right?  I can see dt is 0  using a probe on the output of the Read Measurement Function..   I have attached a sample .lvm file but I have changed the extension because this site would not accept a .lvm file!
    Phil
    Attachments:
    Profile.xls ‏6 KB

    Jeff B,
    Sorry for the delay, I have been travelling for a couple of weeks.  I took a look at the profile and your are right, it was modified incorrectly.  When the data are taken and stored as a CSV file using Write to Labview Data file, the program always sets the sample number to 1 because it is being called to append one sample each time through the timing loop.  Since the number of samples is wrong, I was modifying the number aftewards to get the read to work.  After your comment, I used jedit to modify it rather than excel and it worked.   I could change the program to store the data only once after the run is finished to eliminate having to mess with the data.  I don't know how else to fix it.
    Thanks,
    Phil

  • LabVIEW for ARM 2009 Read from text file bug

    Hello,
    If you use the read from text file vi for reading text files from a sdcard there is a bug when you select the option "read lines"
    you cannot select how many lines you want to read, it always reads the whole file, which cause a memory fault if you read big files!
    I fixed this in the code (but the software doesn't recognize a EOF anymore..) in CCGByteStreamFileSupport.c
    at row 709 the memory is allocated but it tries to allocate to much (since u only want to read lines).
    looking at the codes it looks like it supposed to allocated 256 for a string:
    Boolean bReadEntireLine = (linemode && (cnt == 0)); 
    if(bReadEntireLine && !cnt) {
      cnt = BUFINCR;    //BUFINCR=256
    but cnt is never false since if you select read lines this is the size of the file!
    the variable linemode is also the size of the file.. STRANGE!
    my solution:
    Boolean bReadEntireLine = (linemode && (cnt > 0));  // ==
     if(bReadEntireLine) {    //if(bReadEntireLine && !cnt) {
      cnt = BUFINCR;
    and now the read line option does work, and reads one line until he sees CR or LF or if the count of 256 is done.
    maybe the code is good but the data link of the vi's to the variables may be not, (cnt and linemode are the size of the file!)
    count should be the number of lines, like chars in char mode.
    linemode should be 0 or 1.
    Hope someone can fix this in the new version!
    greets,
    Wouter
    Wouter.
    "LabVIEW for ARM guru and bug destroyer"

    I have another solution, the EOF works with this one.
    the cnt is the bytes that are not read yet, so the first time it tries to read (and allocate 4 MB).
    you only want to say that if it's in line mode and cnt > 256 (BUFINCR) cnt = BUFINCR
    the next time cnt is the value of the bytes that are not read yet, so the old value minus the line (until CR LF) or if cnt (256) is reached.
    with this solution the program does not try to allocate the whole file but for the max of 256.
    in CCGByteStreamFileSupprt.c row 705
     if(linemode && (cnt>BUFINCR)){
       cnt = BUFINCR;
    don't use the count input when using the vi in line mode. count does not make sense, cnt will be the total file size. also the output will be an array.
    linemode seems to be the value of the file size but I checked this and it is just 0 or 1, so this is good
    update: damn it doesn't work!
    Wouter.
    "LabVIEW for ARM guru and bug destroyer"

  • 'read from text file' erases the file

    I am trying to read text in from a text file.  This is the exact code I am using.  For some reason the output from 'read from text file' contains all the text that was originally in the file, but after the code executes the file is empty.  I have several other vi's which use the same code and the file is fine.  But whenever I run this code in this one specific vi the text file gets erased.

    What is in the rest of that "specific vi"? I just tried the code you show, in v2011, and it works as expected, doesn't clear file.
    What version are you running? Can you add an error out, or make sure error output is on in your LabVIEW configuration?
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • UITextField from .xib file doesn't show

    A UITextField from .xib file doesn't show when it's page comes up on the iPhone simulator.
    The View looks fine in Interface Builder, and no warnings are thrown to Console or IB's Info window.
    On the Simulator the View comes up and a Label and a Switch show, but not a UITextField. The Objects are on the same row and their bounds are all appropriate.
    I don't see anything in the Text Field Attributes of IB that is problematic, plus I've probably tried all combinations of settings. In Connections there is a reference to a File's Owner attribute.
    I have been able to create a UITextField programmatically.

    Worked around the problem by deleting the UITextField from the .xib and re-creating it.

  • Read From Measurement File... removes X Values of first column?

    During one of our tests, two instruments were switched at the terminal by accident. I need to read in the massive lvm files, remove the wrong scaling and apply the correct scaling, while switching the values in the columns and right it all to new files. Simple right?
    I wanted to use the Read from Measurement File.vi to make things easier, because the files are very large and I would like to analyze them 100 rows at a time. Some of the the files are around 1.5 Gigs in size so I need to read them in chunks.
    The read from measurement file keeps removing the first column from the data! It outputs the data as a signal (dynamic data) and I have to use the dynamic to numeric array express vi. For some reason, before I even get to that point, the first column is not in the data.
    No matter what settings I pick on the read from measurement express vi, the time column is removed from the data. I have checked/unchecked the "first row is channel names" and "first column is time channel" to no avail. The odd thing is that in the preview it shows the first column, as if it will read it properly... but it doesnt. Nothing I change in the settings can seems to make a difference in getting the first column, the x values, out of the file.
    Below you can see the first column completely removed from the data.
    This is extremely frustrating. By probing the signal out I can see the dynamic data attributes and the time column has already been removed, so I don't think that the signal to double array express vi is the problem, but I am not sure.
    I am attaching my VI and a small data file to be analyzed. You can see what I mean.
    The alternatives seem less than adequate. The read from spreadsheet file vi wants an offset of a specific number of characters not rows. The problem is that this is not constant between rows for some reason, when hidden characters are taken into account so I cant just set the number of characters in 100 rows and increment the offset in a loop... like I normally would. That means I might miss data or get a corrupted row.
    This means that I have to use the read from text file, read how ever many characters I think a row is (over estimating a bit) then search for the newline character, find out how many chars are in that set and then offset that for the next loop iteration, all while converting each string number to a double. Talk about slow.
    I have searched around and found that I am not the only one that has had this issue. This is a common thing, but no one seems to have the answer. Why can't the read from measurement file VI read all of the numbers in every row? Why cant I tell it I want a 2d array of doubles out and not a dynamic data type? It has to be something I am doing wrong.
    Attached is a zip file with my VI and two data files. The "S19_A_DSI_detensioning_c.lvm" is the one generated by my VI (_c meaning corrected). "S19_A_DSI_detensioning.lvm" is the original measurement file. I hope you will pardon my messy VI, it's a quicky.
    Any help you guys can give would be much appreciated.
    [will work for kudos]
    Attachments:
    Scaling Factor Correction.zip ‏1109 KB

    That is a great workaround. The help talked about putting a check next to "read lines" but for the life of me I couldn't find where to do that. I wonder what other VIs have mystery check options in the right mouse click menu. I mean normally options like those are inputs, I thought. I'm going to start right clicking on every VI I drop to see if there are options there I never realized.
    I would still have to use the set file position VI and specify the byte offset right? How would I know where that is? I guess each character is a byte and I would count the characters in the string retrieved and then offset by that amount on the next iteration using a shift register?
    While waiting for help, I ended up using the read from text file and using the match string to look for the new line character, and using the spreadsheet string to array vi, analyzed the files line by line. Thats just because I couldn't easily come up with a regular expression to get 100 lines. It was slow but it worked.
    However, that still really doesn't answer the question of why it is impossible to get the first column with the read from measurement file express VI. Does anyone know? Is this a known bug?
    [will work for kudos]

  • Read from measurement file (wrong values)

    I have a VI where I save data using the ''Write To Measurement File utility''. When I open the .lvm file in the note pad I can see all the data correctly, but when I use the "Read From Measurement File" tool and try tho make a graph the data shown is not correct. Attached the .lvm file and one image of the chart that labview made using the "Read From Measurement File". If you open the lvm in the notepad you can see that the time column goes up to  22 sec. In the chart the time axis goes only up to 7,5 sec. What is going wrong??? Thanks
    Ps: I changed the file .lvm to .txt to attach
    Solved!
    Go to Solution.
    Attachments:
    Chart.jpg ‏688 KB
    teste.txt ‏156 KB

    vitor22 wrote:
    I tryed.
    And how did it turn out?  Saying I tried and not saying how it didn't work doesn't help me help you.
    I was able to do it.  But the X data wasn't correct.  That is because your timestamps aren't regular spaced.  So you can't use a waveform graph.
    You need to use an XY graph.  See the attached code for how to convert the two channels of data (time, your values) into a datatype to feed to the XY graph.
    Attachments:
    Example_VI_BD.png ‏49 KB

  • Read from one file ... and write

    I had written below code to read from a file
    which has input in below format...
    $ filla
    % dillla
    I wrote a code to read from the below file and I want to write into another file...
    in another format...like
    filla, $
    dilla, %
    I wrote as below... but my code doesn't work....i commented most of the code becoz I doubt ....
    I read the file...line by line...
    each line has two words one is special characters($ or %) and the other is some name... separated by space..
    I stored both in different arrays...and thought to write them in output file...
    import java.io.*;
    public class data
           public static void main(String args[])
                int kMaxLines = 60000;            
                  String[][] valuePairs = new String[2][kMaxLines];
                  String symbol [] = new String[kMaxLines];
               String name [] = new String[kMaxLines];
               int k = 0;
                       try            
                      FileInputStream fstream = new FileInputStream("c:/inputs.txt");
                      DataInputStream datastream = new DataInputStream(fstream);
                      BufferedReader br = new BufferedReader(new InputStreamReader(datastream));
                      //FileWriter output = new FileWriter("c:/output.txt");
                 //BufferedWriter bw = new BufferedWriter(output);
                      String names; 
                      String strLine;
                      int line = 0;
                      while ((strLine = br.readLine()) != null)
                           String temp_strs[] = strLine.split(" ");
                          for (int j = 0; j < 2; j++)
                          valuePairs[j][line] = temp_strs[j];
                         //System.out.println(temp_strs[0] + " " + temp_strs[1]);
                          symbol[k]= temp_strs[0];  
                          name[k]=temp_strs[1];
                          line++;
                          k++;
                      for (k=0; k < kMaxLines; k ++)
                      System.out.println(symbol[k]+ "" + name[k]); // when I print it is giving null value...
                      } // so what I do to get those values into global array...
                          datastream.close();
                // to write to file
                   //String names_str;
                        //bw.write("@relation train");
                  //for(k=0; k<kMaxLines; k++)
                    //  names_str = names+""+name[k];
                   //bw.write("@attribute names" + " {"+names_str+"}");
                   //bw.write("@attribute class {+,-}");
                   //bw.write("@data"+"\n");
                    // for (k=0;k<kMaxLines; k++)
                   //bw.write("name[k]+","+symbol[k]");
                       catch (Exception e)
                      //file not found exception...
                            e.printStackTrace();
     

    Why the multiple arrays?
    I'd just read it into List<String[]>... an extensible collection of "the fields on each line"... then you just write them out as required.
        second-field + comma + first-field.
    I suggest your next move should be to take a backup copy of your current class then rip-all that commented-out code out of it, and reformat it properly... starting from a clean(er) slate... then try swapping over to a List<String[]> instead of that cumbersome String[][] matrix.
    Try that... if you get stuckeroonied then don't be afraid to ask again.
    Cheers. Keith.

  • Regular expressions read from a file?

    Hello,
    I'm trying to read a bunch of string literals from a file, and then replace their appearances in another string. It works, except when I have special characters in the file, like this:
    (hello)
    When I use that in Pattern.compile(), it obviously thinks that the parenthesis are not literal. So, I edited my text file and changed the line to:
    \\(hello\\)
    No change. It will not match the string at all. I've even tried this (just out of deperation):
    \\\\(hello\\\\)
    It just doesn't seem I can escape it right if the expression is being read from a file.
    What am I doing wrong?

    Another idea: I tried the following
    import java.io.*;
    public class RegexTest {
        public static void main(String[] args) {
            try {
                File input = new File("pattern.txt");
                FileReader in = new FileReader(input);
                int c;
                StringBuffer buf = new StringBuffer();
                try {
                    c = in.read();
                    while (c != -1) {
                        if (!Character.isWhitespace((char)c)) {
                            buf.append((char) c);
                        c = in.read();
                    System.out.println(buf.toString());
                } catch (IOException iox) {}
                String previous = "(hello) test test test";
                System.out.println(previous);
                System.out.println(previous.replaceAll(buf.toString(), "test"));
         } catch (FileNotFoundException nfnx) {}
    }and it works properly.
    I found out that if the input line with the "\(hello\)" pattern ends with the usual CRLF the only way to have the expected results is to filter out the extra characters (using the !Character.isWhitespace((char)c) test).
    Does this give you any help?

  • EOF detection in "Read From Spreadsheet File"

    Hi folks, I need help in detecting EOF in a "Read From Spreadsheet File". I' d like to stop a while loop by wiring the EOF? indicator to the stop condition, but this doesn't work. For design resons I can't substitute the while loop with a for loop and I DO need the while loop. I read something about creating custom EOF detection but I'm wondering why the builtin function in the vi doesn' t work and if there isn't some simple solution. Many thanks, hazibuli  

    I'm guessing that you want to process one line at a time from the spreadsheet.  Use Read From Spreadsheet File to read in the entire spreadsheet as Dennis says.  Then wire the 2D output to a For Loop with indexing enabled.  Each iteration of the For Loop will allow you to process one line at a time.  When the last line is processed, the For Loop will exit automatically.  Here is an example to get string length of each element in a spreadsheet. Message Edited by tbob on 03-15-2010 09:46 AM

  • Examine and repair iphoto library files doesn't work?

    examine and repair iphoto library files doesn't work?

    As a Test:
    In the Source account - create a new library and try share it instead.
    Hold down the option (or alt) key and launch iPhoto. From the resulting menu select 'Create Library'
    Import a few pics into this new, blank library. Is the Problem repeated there?

  • UPDATE : Toshiba Recovery Wizard 'cannot read from source file or disk' error (satellite L500)

    UPDATE 2: Phoned Toshiba tech support again, guided by techie to begin the recovery again. Just before phoning I was able to go into recovery options and view the drive setup and all the files that couldn't be read are on the CD so I've no idea why the error kept occuring, and neither did the techie. Fingers crossed it works this time but I'm not overly hopefully given that we've just done exactly the same as I did before.  UPDATE 1: I got into the BIOS and reset everything back to defaults and yay, my toshiba recovery wizard now starts! :-D  On the down side, when trying to do a factory default software / out of the box recovery I continually get error messages with regards to copying the files, for example 
    cannot read from source file or disk
    7z.dll
    Type application extension
    size 585kb
    date modified 7/14/2009 10.26pm
    other read / copy errors include PREINST6.SWM, BOOT_32, BOOTPRIORITY, CHECKMAXPTSIZE, CHGBOOT, CPU, CPUCHECK, CREATEPARTITION, CTRLDRVINFO, DISKWIPE, DMI, DPINST32, EBLIB.DLL, ERRORDIALOG, EW3BOOTSEQ, FWLINK, FWLINK.SYS, GETHDDINFO, GETKEYSTATE, IMAGEX, INFILED, INITRECAREA, KRAIADAPI.DLL ..... at which point I decided to 'skip all' :-/
    Any explanations as to what's going on and how I might be able to fix it would be very much appreciated! :-)  Thank you!
    I have a two and half year old satellite L500 with an Intel i-3 and 4 gigs of RAM, on which I was running Windows 7.
    Admittedly it’s had rather a hard life (I ran some very demanding CAD / graphics software on it) but it had always performed well until just recently, when after suffering several BSOD (which had never happened before), the hard drive failed.
    I partitioned and formatted a brand new hard drive (which is perfectly fine and functions normally when hooked up to another laptop with a SATA to USB cable) and obtained system recovery discs from Toshiba.  Unfortunately, when I try and run the first disc, windows starts to load files but then generates an error screen with the message Error F3-F100-0003 and a request to turn the computer off.  
    When I use the windows Memory Diagnostic to get into the Windows Boot Manager Screen I get the following;
    Windows failed to start.  A recent hardware / software change might be the case.
    To fix the problem
    Insert your windows installation disc and restart your computer
    Choose your language settings and click ‘next’
    Click ‘repair your computer’
    File: \boot\memtest.exe
    Status: 0xc000000f
    Info: the selected entry could not be loaded because the application is missing or corrupt.
    I can also use F8 on startup to get into the advanced boot options but selecting any of them simply results in the F3-F100-0003 error message.  I’ve run a memory test using the UBCD, which tells me the memory is fine, and tried another hard drive (which also works perfectly well in another laptop) but no joy.  On phoning Toshiba support the techie said my hard drive had failed, but as I say, both hard drives are perfectly fine / usable when hooked up to another laptop.  I’m now completely stuck as to what the problem is and how I might resolve it – any advice / suggestions would be most gratefully received! Thank you in advance :-)

    Satellite L655-S5096
    Downloads here.
    the second disc gives me the the "cannot read from source file or disk PREINST8.SWM"
    My best guess is that the disc is not readable. Try copying it to another. Sometimes that works.
    Otherwise, order new discs from Toshiba.
    -Jerry

Maybe you are looking for