Getting constants from .h files in Java

Hi all,
if we have a .h file with a number of constants that we wish to use in some Java source code, is it possible to get these values without having to redefine them in Java?
I'm thinking along the lines of using JNI to read the file and get the values and using them when needed.
E.g.
in a .h file I have
const int A_CONST = 0;
const int B_CONST = 1;and I want to have a Java source file which can do something like;
System.out.println("the value is "+A_CONST);Is this possible or would I have to read the file as ordinary text?
Regards,
John

$ cat a.c
#define const private final static
const int A_CONST = 0;
const int B_CONST = 1;$ gcc -E -P a.c
private final static int A_CONST = 0;
private final static int B_CONST = 1;

Similar Messages

  • Cant get data from text file to print into Jtable

    Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
    void dbTest() {
    DataInputStream dis = null;
    String dbRecord = null;
    String hold;
    try {
    File f = new File("customer.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    Vector dataVector = new Vector();
    Vector headVector = new Vector(2);
    Vector row = new Vector();
    // read the record of the text database
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ",");
    while (st.hasMoreTokens()) {
    row.addElement(st.nextToken());
    System.out.println("Inside nested loop: " + row);
    System.out.println("inside loop: " + row);
    dataVector.addElement(row);
    System.out.println("outside loop: " + row);
    headVector.addElement("Title");
    headVector.addElement("Type");
    dataTable = new JTable(dataVector, headVector);
    dataTableScrollPane.setViewportView(dataTable);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error!" + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
    try {
    dis.close();
    } catch (IOException ioe) {
    } // end if
    } // end finally
    } // end dbTest

    Here's a thread that loads a text file into a JTable:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172
    And my reply in this thread shows how you can use a text file as a simple database:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=342380

  • How to get data from a file?

    Hello everyone, i'm new to this forum and to java too. Ok, so here is what i want to do:
    I want to get data from a file containing words and numbers and store them into variables that i will use them after to insert into a database table. For example i have a file called employees.txt in this form:
    eid ename zipcode Hire_date
    1000 "Jones" 67226 "12-DEC-95"
    In C++ i declare variables for each data and store them, for example in this case:
    ifstream in("somefile");
    string name, hdate;
    int eid, zip;
    in >> eid >> ename >> zip >> hdate;
    So i want to do the same thing in JAVA but i can't make it work. So, i would appreciate if someone could give me a simple example how to do it. Thank you.

    [http://java.sun.com/docs/books/tutorial/essential/io/index.html]

  • Passing Parameters from XML file to Java Application

    Can any one help me to know the way of passing values from XML file to Java Application..
    Thanx in advance

    With the Processing Instructions <?name pidata?>
    Get the Nodes in a Document.
    Node node;
    if(node.getNodeType()==Node.PROCESSING_INSTRUCTION_NODE)
    //String param=node.getData();

  • How to get Text from (.txt) file to display in the JTextArea ?

    How to get Text from (.txt) file to display in the JTextArea ?
    is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...

    public static void readText() {
      try {
        File testFile = new File(WorkingDirectory + "ctrlFile.txt");
        if (testFile.exists()){
          BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
          String s = br.readLine();
          while (s != null)  {
            System.out.println(s);
            s = br.readLine();
          br.close();
      catch (IOException ex){ex.printStackTrace();}
    }rykk

  • TS3771 Why can't I select "get info" from the file area so I can change the setting to "open in 32-bit mode" ?

    Why can't I select "get info" from the file area so I can change the setting to "open in 32-bit mode" ?

    It may be because of your settings. You can modify that setting in System Preferences > Trackpad. Another way of making right-click is to click the app icon while holding the Control key

  • Read lines from text file to java prog

    how can I read lines from input file to java prog ?
    I need to read from input text file, line after line
    10x !

    If you search in THIS forum with e.g. read lines from file, you will find answers like this one:
    Hi ! This is the answer for your query. This program prints as the output itself reading line by line.......
    import java.io.*;
    public class readfromfile
    public static void main(String a[])
    if you search in THIS forum, with e.g. read lines from text file
    try{
    BufferedReader br = new BufferedReader(new FileReader(new File("readfromfile.java")));
    while(br.readLine() != null)
    System.out.println(" line read :"+br.readLine());
    }catch(Exception e)
    e.printStackTrace();
    }

  • Possible to get length from midi files?

    Is it possible to retrieve the length from a midi file, for example in miliseconds?

    And how is that helping me?So my taking my limited free time to consider your question, do a search on google, and pull up a very appropriate article -- all as a volunteer mind you -- is not helpful?
    A word of advice: you will have a much greater chance of getting more help if you show appreciation for anyone who takes the time out to consider your problem and offer any even remotely useful solution.
    just my 2 Shekel's worth...
    It explains how MIDI format is built...
    I am no pro as you may understand, because I posted
    in "New To Java".And I can magically read your mind and know exactly where you are in your java development? Sorry, I left my mind-reading cap at work. You were not exactly detailed in what you were seeking, what you know, and what you've found so far. Another word of advice: try to put as much effort into asking your question as you'd like someone would to answer it.
    And I know you can get length of .wav files for
    example by using Clip. That's why I am asking if
    there's a way for midi files as well. Like a method
    for AudioStream or whichever.I hope you find your method. But this is all the help you are going to get from me. Geeze...

  • Getting input from a file(user I/O redirection)

    alright i am stuck on this program. Heres what i have to do
    I have to write a program usinbg arrays and looping. The program should get its input from a file (user I/O redirection). The first number in the file will be the number of numbers that follow to find the average of (maximum of 100) and print if they are above or below the average.
    I have called the program lab9.java. I already made a file called lab9.dat. This is whats inside the lab9.dat file.
    16
    15
    751
    24
    -56
    81
    227
    54
    99
    0
    102
    57
    58
    43
    245
    47
    73
    16 is how many numbers i am using.
    I am just stuck on how i should do this.
    I have to have the program look at those numbers from that file and then calculates the average and then it has to look at each individual number and print out if that number is above or below average. First off im getting an error when i put in java lab9 < lab9.dat. Am i messing up somewhere.
    I also have the loop:
    int numnums = cisio.GetInt();
    double nums[] = new double[numnums];
    int k;
    for(k=0;k<numnums;k++)
    nums[k]=cisio.GetInt();
    This is where im stuck. I need the program to get the average of the numbers and then compare each number to the average and say if its above or below average. I dont know how to do that. If someone can help me out that would be great.

    Yes, you would need three loops: one to get the input, other the calculate the sum, and a third to print out what numbers are less than and what more than the average. That is the easiest thing to do. It's possible to combine getting the input and calculating the sum in one single loop though. I'm glad you got it working! :)

  • Help Me... How to get Data from CSV File...?

    Hi Everyone..!
    This is yajiv and am working in CS3 Photoshop platform. I know about Java Script. Is it possible to get the data from CSV files. Actually our client use to send us the CSV files which contains a lot of swatch name and reference files in one particular image name.
    Actually how we work on that CSV file is, first we copy file name to search that CSV file. then get the result to paste into layer name. This process continue till the end of swatch.
    Thank in Advance
    -yajiv

    > Is it possible to get the data from CSV files.
    Have you tried searching this forum?

  • How to get info from imported file in an outbound campaign IVR-based. UCCX 8.5.

    Hello.
    Somebody knows if it is possible to get the information inside my ivr script from the file imported when I create an outbound campaign IVR-based?
    I want to store in variable data like first name, last name, account number... And use them in the flow of my IVR script.
    I´m using UCCX 8.5.
    Regards

    did you get this to work ?

  • How to get data from XML file having korea Text

    I have a one XML File with Korean Text, How to read this File.
    i tried with this code
    BufferedReader in = new BufferedReader(
    new InputStreamReader(new FileInputStream("C:/test1.xml"), "EUC-KR"));
    String str = in.readLine();
    but it is giving exceptions.
    please suggest me, how to retrive EUC-KR text from the XML file

    Standard Java does not support this Charset. You have to find a charset provider that implements "EUC-KR". But you should also consider using Unicode, which is implemented in standard Java.
    http://www.unicode.org/charts/

  • Read & write from external files in java

    Hello everybody,
    I need your help in two problems. I have to write a method that read specific numbers from a file, save them in an array, do some calculation on that array and write it again in a new file.
    For example, I have a file that contains the following:
    #VRML V1.0 ascii
    Material {
    diffuseColor [ 1 1 1 ]
    ShapeHints {
    vertexOrdering COUNTERCLOCKWISE
    shapeType UNKNOWN_SHAPE_TYPE
    Coordinate3 {
    point [
              1 0 0 ,
              1 1 0 ,
              1 1 1 ,
              1 0 1 ,
              0 1 0 ,
              0 1 1 ,
              0 0 1 ,
              0 0 0 ,
    IndexedFaceSet {
    coordIndex [
    0,1,2,-1,
    0,2,3,-1,
    1,4,5,-1,
    1,5,2,-1,
    3,2,5,-1,
    3,5,6,-1,
    0,3,6,-1,
    0,6,7,-1,
    6,5,7,-1,
    7,5,4,-1,
    0,7,4,-1,
    0,4,1,-1,
    I need to read the point coordinates only and save them in a two dimension array, then I'll do some transformation on that array and write it in a new file that contains the previous data but the point coordinates are the transformed coordinates. I tried the following:
    FileReader in = new FileReader("C:\\hexahedron.txt");
              BufferedReader br = new BufferedReader(in);
              String line;
              StringTokenizer s;
              int [][] point = new int [8][3];
              int row = 0;
              int column;
              while ( (line = br.readLine()) != null) {
                   s = new StringTokenizer(line);
                   column = 0;
                   while (s.hasMoreTokens()) {
                        if ( s.nextToken() == "[" ){
                             point [row][column++] = Integer.parseInt(s.nextToken());
                   row++;
              br.close();
              in.close();
    But when I tried it, I found out that it saves 0s in the array!
    As I mentioned before, my problem is that I don't know how to read specific information from a file. I know how to write new information a file, but how to write a file that I already have with changed specific information.
    I'll be grateful if you show me how to solve those problems.
    And I hope that I explained my problems in an understandable and clear way.
    Regards,

    if ( s.nextToken() == "[" ){should beif (s.nextToken().equals("["){Also, you have two nextToken for each has hasMoreTokens, which is going to cause an exception.
    You are never hitting the parseInt code because of your equals/== error. Therefore, everything is zeros.
    The order of reading lines and checking for "[" isn't right. You should find the [ (maybe including the "point" word), then get numbers from the following lines (read line, tokenize, read line, tokenize, ...) until you hit the end of the points.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Sending and getting data from external file.

    I'm running it in actionscript 1  and 2 since 3 wouldn't work when getting data from external media. I'm  trying to find out how to post data to a PHP file and getting from that  file I'm trying to make the flash for something that works like a game  but differently. Since I just found out how to make the HTML stuff show  up but a lot of times, some of my text will not appear so I don't know  what's going on.
    Does anyone know how to send and get data both at the same time from a sample file?
    The sample file is example.php
    It has to sent information like ID and NAME
    and it has to get information like Description and userID

    Ned Murphy wrote:
    The tutorial I pointed you to does provide the visuals you requested, both the AS code and sample PHP code, so I can't see where your learning by visuals aspect holds up.... your approach sounds more like you want someone to hand you a tailored solution that you won't need to learn from.  Visuals require reading and doing.  If that fails to get absorbed or you couldn't understand/revise it, what could anyone else prepare for you that would work better?
    I did the tutorial and everything but every time I press the button or even load it, it keeps on saying undefined. I like the have a sample FLA file so I can figure things out. I did everything from the site but it won't work out for me.
    I did step 5 too because it was almost all that I was looking for but it won't even work. keeps on saying undefined. I would show you but webcam max won't work and I can't show you an example.
    EDIT:
    You know it's frustrating when I don't know how the heck I'm supposed to do this stuff. I read the whole dang thing and I still can't get this dang thing working.
    I did everything. EVERYTHING. I just don't get this crap.

  • How do i get photos from my files to my ipod touch 4G? HELP

    i want the pictures from my files on my ipod but i cant figure it outtttttt

    Hello charlie9517
    To get pictures on your iPod touch, go to the Photos tab within iTunes and select what photos you want on there. For the full list of instructions, the article below will sort you step by step.
    iTunes 11 for Windows: Add photos to iPod, iPhone, or iPad
    http://support.apple.com/kb/PH12316
    Regards,
    -Norm G.

Maybe you are looking for

  • Display not sharp anymore

    Hi, Yesterday i've installed Mountain Lion on my late 2011 Imac. Installation, no problem. Only thing is the display isnt as sharp as it was. When I look youtube clips its like looking in vga mode. Even on 1080 mode its stil not sharp. Cant realy dis

  • How to limit the number of items from RSS using XSLT

    Hello, I am using plsql to read contents from RSS, basically a simple RSS reader. I would like to somehow want the feature to restrict the number of items in the RSS feed, say I would like to display only the first 5 items. How could I achieve this?

  • Using Firefox8 in Ubuntu - Webpages that I bookmark are never saved in the Bookmark list.

    I've been using Firefox on Windows for years without any trouble. Now on Ubuntu and using Firefox. I was able to save two urls to the Bookmark list but now find that any url that I want to bookmark does not get bookmarked or listed in the Bookmark ca

  • "USER" and "FILE" tables

    Our database in Access 2000 has tables named "user" and "file". The Migration Work Bench is converting those to "USER_" and "FILE_". I'm guessing the words are reserved words in Oracle. Is there any way I can adjust the migration script to create the

  • Delta replication of Sales Org, Sales Off and Sales Group (ECC to CRM)

    HI All, I am struck with the delta of the Sales Area. Sales org with 6 Sales Offices and 6 Sales Group were created in the ERP and all this were replicated in to CRM in Initial but now my client wants to add 3 more sales offices with 3 Sales Groups.