FileReader and StringTokenizer

what I'm trying to do is to read String and Double date in a txt document here my code:
import java.io.*;
import java.util.*;
public class partie1 {
     static final int limite_colones=10;
     static final int limite_lignes=10;
     static final int limite_matieres=5;
     static final int limite_eleves=15;
     static final String titre="�cole secondaire Cartierville";
     static String nomEleve[]=new String[limite_eleves];
     static double notesEleve[][]=new double[limite_eleves][limite_matieres];
     public static void main(String[] args)throws IOException {
          String ligne,ficEleve="c:/ficEleves.txt";
          BufferedReader ficnomlogique=new BufferedReader(new FileReader(new File(ficEleve)));
          while ((ligne=ficnomlogique.readLine())!=null){
               StringTokenizer ligneTemp=new StringTokenizer (ligne,":");
               for(int i=0;i<15;i++){
                    nomEleve=ligneTemp.nextToken();
                    System.out.println(nomEleve[i]);
                    for(int j=0;j<5;j++){
                         notesEleve[i][j]=Double.parseDouble(ligneTemp.nextToken());
                         System.out.println(notesEleve[i][j]);
and this is what they give me as error message:
Alain
100.0
90.0
88.0
60.0
65.0
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(Unknow Source)
at partiel.main(partie1.java:20)
so i understand that it doesnt change ligne or doesnt do the for correctly but i can't figure where is my mistake.
thank for your help

What do the records in the file look like?
This code:
for(int i=0;i<15;i++){
    nomEleve=ligneTemp.nextToken();
System.out.println(nomEleve[i]);
for(int j=0;j<5;j++){
notesEleve[i][j]=Double.parseDouble(ligneTemp.nextToken());
System.out.println(notesEleve[i][j]);
will call nextToken() on each line 15 + (15 * 5) = 90 times.
Does each line contain 90 tokens?

Similar Messages

  • File I/O and StringTokenizer

    Hi
    This may be really simple, but I seem to have problem here. I am reading a txt file using FileReader and I am just printing it out. The txt file has lots of lines. What I want now is to take just the lines which has an = sign on it( there should be only one =) and print just that. This line in the txt file is the form key=value(a hashtable) I need to printout just those lines which are of these form key=value and ignore all the lines. I know I should use the StringTokenizer, but how do I read the.txt file and check if there is any blank line or illegal line and select the line with key=value and print it.
    Please let me know.
    Thanks

    yourStuff() is a snippet that you will change with your source code.
    The regular expression is:
    "^\\w+=\\w+$"
    It means: "from starting data input position (^) followed with one or more char in set [a-zA-Z0-9_] (\\w+), followed with an '=', followed with one or more char (\\w+) till the end of data input ($)".
    It assures no more than one '=' in a line but since you can have blankspaces surrounding this char use that: "^\\w+\\s*=\\s*\\w+$".
    The method "matches()" means "exactly matches" and using anchors: ^ and $, ie; exactly matches from start to end of data input.

  • Form feed, null and StringTokenizer

    is form feed recognized as null when using the StringTokenizer?
    i currently have my StringTokenizer set with a blank space and i am attempting to read until the value is (EOF) null and while it hasMoreTokens. the text file that i am reading from spans across several pages. my code falls out of my loop when it hits the last space on my first page.

    a form feed (\f) is not a null but that shouldn't be stopping the StringTokenizer, I suspect that the manner in which you're reading in the data may be the culprit. Try to use the BufferedReader class to read your file.
    V.V.

  • Polynomial and Stringtokenizer

    I'm stuck on a homework problem involving a polynomial. The part I'm stuck on is where you're given a string in the form of a polynomial and you need to split it up into it's different terms.
    One constructor, Polynomial(String poly), is somewhat tricky. For this constructor you must extract the required information from the string passed as an argument. Stylistic issues are important in defining the valid parameters for this constructor.
        * ax^n+bx^(n-1)+c1x^(n-2)+...+d , the string is a valid polynomial.
        * No two terms have the same exponent.
        * No terms with coefficient 0 (2x^2+1 is valid input for 2x^2+0x^1+1).
        * Terms with coefficient of 1 omits the 1 (x^3+x^2 is valid).
        * The x^1 term omits the exponent 1 (2x^3+3x is valid).
        * The x^0 term, the constant term, omits everything but the coeficient (2x^3+3x+1 is valid).
        * There are no occurrences of contiguous plus and minus signs (+- and -+ not allowed).
        * The leading positive sign on the initial term is unnecessary: 5x^2+4x+2 is valid, not +5x^2+4x+2
        * There are no duplicate terms, i.e., there is at most one term for a given power.I think I know where to start, that's using a StringTokenizer. But from there I'm lost. Any help would be greatly appreciated.

    Ordinarily, I would advise against using StringTokenizer for parsing mathematical expressions, but your requirements are so simple that it should suffice.
    You have one or more terms separated by plus or minus signs--that's your delimiter. You have to keep the delimiter (instead of discarding it as StringTokenizer usually does) so you can apply the correct sign to the following term. And you have to handle an optional minus sign at the beginning of the expression (i.e., the first "term" might be the empty string, and should be ignored).
    Does that help?

  • Faster split than String.split() and StringTokenizer?

    First I imrpoved performance of split by replacing the String.split() call with a custom method using StringTokenizer:
                    final StringTokenizer st = new StringTokenizer(string, separator, true);
                    String token = null;
                    String lastToken = separator; //if first token is separator
                    while (st.hasMoreTokens()) {
                        token = st.nextToken();
                        if (token.equals(separator)) {
                            if (lastToken.equals(separator)) { //no value between 2 separators?
                                result.add(emptyStrings ? "" : null);
                        } else {
                            result.add(token);
                        lastToken = token;
                    }//next tokenBut this is still not very fast (as it is one of the "hot spots" in my profiling sessions). I wonder if it can go still faster to split strings with ";" as the delimiter?

    Yup, for simple splitting without escaping of separators, indexOf is more than twice as fast:
        static private List<String> fastSplit(final String text, char separator, final boolean emptyStrings) {
            final List<String> result = new ArrayList<String>();
            if (text != null && text.length() > 0) {
                int index1 = 0;
                int index2 = text.indexOf(separator);
                while (index2 >= 0) {
                    String token = text.substring(index1, index2);
                    result.add(token);
                    index1 = index2 + 1;
                    index2 = text.indexOf(separator, index1);
                if (index1 < text.length() - 1) {
                    result.add(text.substring(index1));
            }//else: input unavailable
            return result;
        }Faster? ;-)

  • Missing Value using HashMap and StringTokenizer

    class StringToken
         String Message = "a b Germany";
         HashMap <String,String> map;
    StringTokenizer token;
         public StringToken()
              try
              token = new StringTokenize(Message);
                   map = new HashMap <String,String>();
                   map.put("a","Adelaide");
                   map.put("b","Auckland");
    while (token.hasMoreToken())
                        System.out.print (map.get(pesan.nextToken())+" ");          
              catch(Exception e)
         public static void main(String[] args)
              new StringToken();
    The output like this :
    Adelaide Auckland null
    What i want like this:
    Adelaide Auckland Germany
    The problem is,How to display all value of Message? cos There's no Germany key..i want to make some condition like this, if there's no key in the Hashmap, the value still displayed originally..
    At my code the problem is, if there's no key in hashmap,output wont display the word..
    Thanks Guys...

    Two options:
    1) Instead of
    System.out.print(map.get(pesan.nextToken()));do
    String token = pesan.nextToken();
    String value = map.get(token);
    if (value==null) value = token;
    System.out.print(value);2) Implement a new Map which provides this behavior.
    Cheers

  • String and stringtokenizer problem

    Hi,
    String s=new String(null);
    is it possible or not?
    StringTokenizer st=new StringTokenizer(null,",");
    is it possible or not?

    hi sudha,
    when u write
    String s=new String(null); is wrong. Just b'coz the method of String(byte()) that are from java.lang.String will match with your declared method.
    so it will have to clashing ...so u will get ERROR dear.
    Regards
    saM

  • StringTokenizer vs. split and empty strings -- some clarification please?

    Hi everybody,
    I posted a question that was sort of similar to this once, asking if it was best to convert any StringTokenizers to calls to split when parsing strings, but this one is a little different. I rarely use split, because if there are consecutive delimiters, it gives empty strings in the array it returns, which I don't want. On the other hand, I know StringTokenizer is slower, but it doesn't give empty strings with consecutive delimiters. I would use split much more often if there was a way to use it and not have to check every array element to make sure it isn't the empty string. I think I may have misunderstood the javadoc to some extent--could anyone explain to me why split causes empty strings and StringTokenizer doesn't?
    Thanks,
    Jezzica85

    Because they are different?
    Tokenizers are designed to return tokens, whereas split is simply splitting the String up into bits. They have different purposes
    and uses to be honest. I believe the results of previous discussions of this have indicated that Tokenizers are slightly (very
    slightly and not really meaningfully) faster and tokenizers do have the option of return delimiters as well which can be useful
    and is a functionality not present in just a straight split.
    However. split and regex in general are newer additions to the Java platform and they do have some advantages. The most
    obvious being that you cannot use a tokenizer to split up values where the delimiter is multiple characters and you can with
    split.
    So in general the advice given to you was good, because split gives you more flexibility down the road. If you don't want
    the empty strings then yes just read them and throw them away.
    Edited by: cotton.m on Mar 6, 2008 7:34 AM
    goddamned stupid forum formatting

  • Using Scanner and FileReader to read from a file in real time

    Hi
    I would like to read continually from a text file (which is continually being appended to) and display each line as it appears in the textfile (in a text area).
    What I would like to know is do I have to continually reopen the file (using FileReader) and buffer it into a Scanner everytime I want to read the changes made to it? There must be a better way.
    Much appreciation for any help.

    Umm .. I hope you're doing that in a separate worker
    thread as otherwise you would block the EDT from
    processing events like paint (thus never showing you
    anything you append to the text area).Well that code fell under the run method of a class that is seperate to the main class, so it was called in a new thread. In desperation I've tried calling threads within threads (dangerous I know): remoteHandler's run method is called by a JButton's action listener...
    private class remoteFHandler implements Runnable {
         int lineNum;
         int  win, x, y, count, num = -999;
         remoteFHandler(){
              lineNum = 0;
         public synchronized void run() {
              while(showScreen == true){
                   readingRF = true;
                   innerHandler read = new innerHandler();
                   Thread t = new Thread(read);
                   t.start();                      
         //Wait 5 a seconds before checking if there is anymore text
                 try {
                         textArea.append("Waiting to reopen \n"); //DEBUG
                   t.join();
                   wait(5000);
                 } catch (InterruptedException e){
                   System.out.println("File reading interrupted");
                   return;
                }// while
              readingRF = false;
              return;
         } //run()
         private class innerHandler implements Runnable{
              innerHandler(){
              public synchronized void run(){
                   try {
                        outFile = new File("/data/wrmwind_08/testText.txt");
                        if (outFile!=null) textArea.append("File last modified: " + outFile.lastModified() + "\n"); //DEBUG
                        fs = new Scanner(new BufferedReader(new FileReader(outFile)));
                        if (fs!=null) textArea.append("File opened stream \n"); //DEBUG
                        fs.useDelimiter("\\r");
                      } catch(IOException e){
                        System.out.println("Problems opening file. IO exception: " + e.toString());
                        return;
                      if (fs!=null){
                        readAndDisplay();
                        fs.close();
                        fs = null;
                        if (fs==null) textArea.append("File closed \n"); //DEBUG
                   return;
         }//innerHandler
            private void readAndDisplay(){ //reads from a file and displays in a text field until there are no new lines  then returns
         }//readAndDisplay()
    }//remoteHandlerThe strange thing is that the when I modify the text file while the program is running, that time of last modification is detected and displayed in the text area yet I can't get to read the new line that's been added....

  • Pattern and Matching question

    Hey,
    I'm trying to use the pattern and matcher to replace all instances of a website
    address in some html documents as I process them and post them. I'm
    including a sample of some of the HTML below and the code I"m using to
    process it. For some reason it doesn't replace the sites in the underlying
    images and i can't figure out what I'm doing wrong. Please forgive all the
    unused variables, those are relics of another way i may have to do this if i
    can't get the pattern thing to work.
    Josh
         public static void setParameters(File fileName)
              FileReader theReader = null;
              try
                   System.out.println("beginning setparameters guide2)");
                   File fileForProcessing=new File(fileName.getAbsolutePath());
                   //wrap the file in a filereader and buffered reader for maximum processing
                   theReader=new FileReader(fileForProcessing);
                   BufferedReader bufferedReader=new BufferedReader(theReader);
                   //fill in data into the tempquestion variable to be populated
                   //Set the question and answer texts back to default
                   questionText="";
                   answerText="";
                   //Define the question variable as a Stringbuffer so new data can be appended to it
                   StringBuffer endQuestion=new StringBuffer();//Stringbuffer to store all the lines
                   String tempQuestion="";
                   //Define new file with the absolutepath and the filename for use in parsing out question/answer data
                   tempQuestion=bufferedReader.readLine();//reads the nextline of the question
                   String tempAlteredQuestion="";//for temporary alteration of the nextline
                   //while there are more lines append the stringbuffer with the new data to complete the question buffer
                   StringTokenizer tokenizer=new StringTokenizer(tempQuestion, " ");//tokenizer for reading individual words
                   StringBuffer temporaryLine; //reinstantiate temporary line holder each iterration
                   String newToken;   //newToken gets the very next token every iterration?  changed to tokenizer moretokens loop
                   String newTokenTemp;   //reset newTokenTemp to null each iterration
                   String theEndOfIt;  //string to hold everything after .com
                   char[] characters;  //character array to hold the characters that are used to hold the entire link
                   char lastCharChecked;
                   Pattern thePattern=Pattern.compile("src=\"https:////fakesite.com//ics", Pattern.LITERAL);
                   Matcher theMatcher=thePattern.matcher(tempQuestion);
                        while(tempQuestion!=null) //every time the tempquestion reads a newline, make sure you aren't at the end
                             String theReplacedString=theMatcher.replaceAll("https:////fakesite.com//UserGuide/");     
                             //          temporaryLine=new StringBuffer();
                             //add the temporary line after processed back into the end question.
                             endQuestion.append(theReplacedString);                              //temporaryLine.toString());
                             //reset the tempquestion to the newline that is going to be read
                             tempQuestion=bufferedReader.readLine();
                             if(tempQuestion!=null)
                                  theMatcher.reset(tempQuestion);
                             /*newTokenTemp=null;
                             while(tokenizer.hasMoreTokens())
                                  newToken=tokenizer.nextToken(); //get the next token from the line for processing
                                  System.out.println("uhhhhhh");
                                  if(newToken.length()>36)  //if the token is long enough chop it off to compare
                                       newTokenTemp=newToken.substring(0, 36);
                                  if(newTokenTemp.equals("src=\"https://fakesite.com"));//compare against the known image source
                                       theEndOfIt=new String();  //intialize theEndOfIt
                                       characters=new char[newToken.length()];  //set the arraylength to the length of the initial token
                                       characters=newToken.toCharArray();  //point the character array to the actual characters for newToken
                                       lastCharChecked='a';  // the last character that was compared
                                       int x=0; //setup the iterration variable and go from the length of the whole token back till you find the first /
                                       for(x=newToken.length()-1;x>0&&lastCharChecked!='/';x--)
                                            System.out.println(newToken);
                                            //set last char checked to the lsat iterration run
                                            lastCharChecked=characters[x];
                                            //set the end of it to the last char checked and the rest of the chars checked combined
                                            theEndOfIt=Character.toString(lastCharChecked)+theEndOfIt;
                                       //reset the initial newToken value to the cut temporary newToken root + userguide addin, + the end
                                       newToken=newTokenTemp+"//Userguide"+theEndOfIt;
                                  //add in the space aftr the token to the temporary line and the new token, this is where it should be parsed back together
                                  temporaryLine.append(newToken+" ");
                             //add the temporary line after processed back into the end question.
                             endQuestion.append(temporaryLine.toString());
                             //reset the tempquestion to the newline that is going to be read
                             tempQuestion=bufferedReader.readLine();
                             //reset tokenizer to the new temporary question
                             if(tempQuestion!=null)
                             tokenizer=new StringTokenizer(tempQuestion);
                   //Set the answer to the stringbuffer after converting to string
                   answerText=endQuestion.toString();
                   //code to take the filename and replace _ with a space and put that in the question text
                   char theSpace=' ';
                   char theUnderline='_';
                   questionText=(fileName.getName()).replace(theUnderline, theSpace);
              catch(FileNotFoundException exception)
                   if(logger.isLoggable(Level.WARNING))
                   logger.log(Level.WARNING,"The File was Not Found\n"+exception.getMessage()+"\n"+exception.getStackTrace(),exception);
              catch(IOException exception)
                   if(logger.isLoggable(Level.SEVERE))
                   logger.log(Level.SEVERE,exception.getMessage()+"\n"+exception.getStackTrace(),exception);
              finally
                   try
                        if(theReader!=null)
                             theReader.close();
                   catch(Exception e)
    <SCRIPT language=JavaScript1.2 type=text/javascript><!-- if( typeof( kadovInitEffects ) != 'function' ) kadovInitEffects = new Function();if( typeof( kadovInitTrigger ) != 'function' ) kadovInitTrigger = new Function();if( typeof( kadovFilePopupInit ) != 'function' ) kadovFilePopupInit = new Function();if( typeof( kadovTextPopupInit ) != 'function' ) kadovTextPopupInit = new Function(); //--></SCRIPT>
    <H1><IMG class=img_whs1 height=63 src="https://fakesite.com/ics/header4.jpg" width=816 border=0 x-maintain-ratio="TRUE"></H1>
    <H1>Associate Existing Customers</H1>
    <P>blahalbalhblabhlab blabhalha blabahbablablabhlablhalhab.<SPAN style="FONT-WEIGHT: bold"><B><IMG class=img_whs2 height=18 alt="Submit a

    If you use just / it misinterprets it and it ruins
    your " " tags for a string. I don't think so. '/' is not a special character for Java regex, nor for Java String.
    The reason i used
    literal is to try to force it to directly match,
    originally i thought that was the reason it wasn't
    working.That will be no problem because it enforces '.' to be treated as a dot, not as a regex 'any character'.
    Message was edited by:
    hiwa

  • Help on reading from and writing to a file !!!!!!!!!!!!!!!!

    hi there
    anyone can help me on how to write and read from a file? how can i read one string at a time instead of a char. thank you.

    You can do this with classes FileReader and FileWriter directly, but it's easiest to wrap these with other classes and call methods on those to read and write a string. All of the classes used below are in the java.io package. The code fragments just print any I/O exceptions to stderr. Replace filename with the name of the file you want to use.
    To write a string to a file:
    String s = "hello";
    try {
    FileWriter fw = new FileWriter("filename");
    PrintWriter pr = new PrintWriter(fw);
    pr.println(s); // write a string with a newline at the end
    // pr.print(s); // write a string without a newline at the end
    pr.close(); // must close for string to be written
    } catch (IOException e) {
    System.out.println(e);
    To read a string from a file:
    String s;
    try {
    BufferedReader br = new BufferedReader(new FileReader("filename"));
    s = br.readLine();
    } catch (IOException e) {
    System.out.println(e);

  • File I/O and encoding (J2SDK 1.4.2 on Windows)

    I encountered a strange behavior using the FileReader / Writer classes for serializing the contents of a java string. What I did was basically this:
    String string = "some text";
    FileWriter out = new FileWriter(new File("C:/foo.txt"));
    out.write(string);
    out.flush();
    out.close();In a different method, I read the contents of the file back:
    FileReader in = new FileReader(new File("C:/foo.txt"));
    StringWriter out = new StringWriter();
    char[] buf = new char[128];
    for (int len=in.read(buf); len>0; len=in.read(buf)) {
        out.write(buf, 0, buf.length);
    out.flush(); out.close(); in.close();
    return out.toString();Problems arise as soon as the string contains non ascii characters. After writing and reading, the value of the string differs from the original. It seems that different character encodings are used when reading and writing, although the doc states that, if no explicit encoding is specified, the platform's default encoding (in my case CP1252) will be used.
    If I use streams directly instead of writers, it does not work, either, as long as I do not specify the encoding when converting bytes to strings and vice versa.
    When I specify the encoding (no matter which one, as long as I specify the same for reading as for writing), the resulting string is equal to the original one.
    If I replace the FileReader and Writer by StringReader and StringWriter (bypassing the serialization), it works, too (without specifying the encoding).
    Is this a bug in the file i/o classes or did I miss something?
    Thanks for your help
    Ralph

    first.... if you are writing String objects via serialization, encoding doesn't matter whatsoever. Not sure you were saying you tried that, but just for future reference.
    For String.getBytes() and String(byte[]) or InputStreamReader and OutputStreamWriter: If you don't specify an encoding, the system default (or default specified on the command-line or set in some other way) will be used in all cases.
    For byte streams: If you are reading/writing bytes thru streams, then the character conversion is up to you. You call getBytes on a string or create a string with the byte[] constructor.
    For readers/writers: If you are reading/writing characters thru readers/writers, then the character conversion is done by that class.
    However, StringReader and StringWriter are just writing to/from String objects and they are writing Unicode char's, so it's really a special case.
    Okay...
    So if you have a string which has characters outside the range of the encoding being used (default or explicitly specified), then when it's written to the file, those characters are messed up. So say you have a Chinese character which needs 2 bytes. Generally, the 2 bytes are written, but when read back, that one character shows as 2. Whether 2 bytes are written or 1, probably depends on the encoding. But the result is the same, you get a munged up string.
    Generally speaking, you are going to get better storage on most text when using UTF-8 as your encoding. You need to specify it always for reads and writes, or set it as the default. The reason is that chars are written in as many bytes as needed. And it'll support anything Unicode supports, thus anything String supports.

  • Need code example for StringTokenizer to hashmap...

    I am creating a rolodex with name, phone, address, city, state. The data will be saved to a delimited file. When the app begins I have to read the file to get the records into memory. My GUI will list the names. The user should be able to click on one of the names to open a dialog box in which all the fields will appear and wil be editable.
    I need some assistance with design...
    I think I should use BufferedReader and StringTokenizer for reading the file in. Then perhaps store the records in a hashmap(need help with that - Is hashmap the thing to use? Maybe arraylist instead? How do i do it?) The records should be stored sorted by name in memory and in the file. Next, I figure I can show the names using a table and hide the other columns, when a cell is clicked I can pop up the dialog box with all the goodies in it. When I save it should be to memory, how do I do that? Then when the app closes I will write out using PrintWriter.
    There are other things going on, buttons, listeners, etc. but the basic design is what I need advice on. Any ideas are welcome and appreciated!

    From the name to get the record, clearly you need a effecient lookup mechnism.
    HashMap does hash lookup, that is right, but HashMap does NOT do ordering.
    TreeMap does binary lookup, TreeMap also does ordering.
    There you go the basic design.
    --lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Text, Searching, and Replacing

    After looking at the API's for String, StringBuffer, and StringTokenizer I am not sure how to accomplish my task. I have a StringBuffer that contains the contents of a file. I want to search in that StringBuffer for text '<servlet-name>Name</servlet-name>', then continue searching to the next occurence of '</servlet>', then insert several lines of text before '</servlet>'. The text I am searching is not always in the same position in each file I am reading. I sure would appreciate a point in the right direction.
    Thanks much!
    Zach

    Since you're working with an XML file the cleanest but disruptive and heavyweight solution would be to parse the file into a DOM tree, modify the tree and render it back out to a file. Let me know if you want to discuss this approach further.
    If you prefer to proceed with text-only modification, you could do the following:
    1 Read the file into a StringBuffer
    2 Get a String view using StringBuffer.toString()
    3 Use String.indexOf() twice to find the right place to insert your additional lines
    4 Use StringBuffer.insert() to add your text
    5 Write the StringBuffer back to a file.

  • How can I pass a file refnum into and out of external c++ code? What type does it convert to in c++?

    I am trying to write external c++ code that will read a file already opened by Labview and therefore assigned a refnum. (Unfortunately, I definately can't use the standard Labview vis.) However I am not sure what c++ type to use in order to manage the refnum.
    All help and thoughts appreciated. Thanks,
    Joanna

    You could do ALL your file handling in C or C++ (MFC CFile for
    example) and pass Microsoft file handles into and out of LabVIEW
    instead of LabVIEW file references into and out of C. This may be an
    easier way to attack the problem.
    You could create a DLL in MSVC that exports a FileOpen function, a
    FileClose function and a FileRead and/or FileWrite Function and then
    call that DLL from place to place as required in your code.
    It would help us if you would explain what kind of data you are trying
    to read or write and what the application is. Is it binary data?
    text files? Do you need some special Win32 file system feature like
    file mapped memory? I guess what I am asking is what is your
    motivation for doing file handling in C or C++?
    Douglas De Clue
    LabVIEW developer
    [email protected]
    "Rolf" wrote in message news:...
    > A LabVIEW file refnum is an internal Magic Cookie to LabVIEW and there is no
    > way to directly extract the actual information assigned to that Magic
    > Cookie.
    > However the CIN Reference Manual describes one function which allows to
    > retrieve a lower level "File" handle and at least on Windows 32 bit and
    > LabVIEW
    > from version 5 up to and including 6.1 this "File" LabVIEW datatype directly
    > maps
    > to the Win32 API "FILE" Handle.
    >
    > The function to use is
    >
    > MgErr FRefNumToFD(LVRefNum refNum, File *fdp);
    >
    > It is declared in extcode.h or one of its dependant headers and exported
    > from "labview.lib"
    > all located in the cintools directory and you can link this lib also to a
    > normal DLL project.
    > However calling this DLL then from any other process than LabVIEW or a
    > LabVIEW
    > executable will not initialize the DLL anymore correctly.
    >
    > Your best option if you need to write in C(++) should be to use the LabVIEW
    > file manager
    > functions described on the External Code Manual (manual/lvexcode.pdf) on
    > this File handle.
    > If you need to use directly some Win32 API functions with it please note
    > that although currently
    > the "File" in the LabVIEW file manager functions matches the FILE in Windows
    > 32 bit API
    > functions this is an undocumented and hence unsupported feature. The next
    > LabVIEW version
    > may actually use a different datatype for its "File" parameter to the
    > LabVIEW file manager calls
    > and your use of assuming File == FILE may simply crash.
    >
    > Also operating on a file refnum in LabVIEW which has been accessed directly
    > with Win API
    > functions may result in strange behaviour such as the file read/write mark
    > not being updated as
    > you would maybe expect it.
    >
    > "Jo" wrote in message
    > news:50650000000800000016520000-1023576873000@exch​ange.ni.com...
    > > How can I pass a file refnum into and out of external c++ code? What
    > > type does it convert to in c++?
    > >
    > > I am trying to write external c++ code that will read a file already
    > > opened by Labview and therefore assigned a refnum. (Unfortunately, I
    > > definately can't use the standard Labview vis.) However I am not sure
    > > what c++ type to use in order to manage the refnum.
    > > All help and thoughts appreciated. Thanks,
    > > Joanna

Maybe you are looking for