🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.softwaretools
3 messages
3 total messages Started by adige Thu, 18 Dec 1997 00:00
NEED TO CONVERT Java to C (a simple file I/O program)
#17
Author: adige
Date: Thu, 18 Dec 1997 00:00
109 lines
4840 bytes
Help is greatly appreciated by Vikram Adige at 212.275.1666.

I need to convert a simple Java program (JDK1.1.4 compatible) to its
Win95/NT equivalent C program.  Can anyone help me do this, or suggest
another course of action.

I want to run the eventual executable independent of a Java VM, and
do not possess an IDE to convert the Java class file to a standalone
Windows executable.

So my alternative is to create an ANSI C equivalent program (that
hopefully compiles with the freely available HP-UX cc compiler).

Below is the source code....

import java.io.*;

/*
 *  Created 12/14/97 by Vikram Adige. PURPOSE: To run during computer
 *  startup, obtain the username from the file config.txt, and insert
 *  it into the orawin.ini file in the "USERNAME=" line.  If the line
 *  does not exist, it must be created.
 */

class FileBuffer {

  public static void main(String[] args) {

    BufferedReader dataNameStream;
    BufferedReader dataInStream;
    StringBuffer namespace, workspace;
    BufferedWriter dataOutStream;
    String nStr, aStr, insertString, marker, replaceMarker;
    String userStr = new String();
    int locator;
    int found = 0;
    String temp;
    int markerLength;

    // get the user's name
    try {
        dataNameStream= new BufferedReader( new FileReader
("c:/jdk1.1.4/lib/extra.ini"));
        namespace= new StringBuffer(300);
        nStr = dataNameStream.readLine();
        nStr = dataNameStream.readLine();
        namespace = namespace.append(nStr);
        userStr = namespace.toString().substring(12,nStr.length());
        dataNameStream.close();
    }
    catch (FileNotFoundException ex) {
        System.out.println("NAME SEARCH File not found");
    }
    catch (IOException ex) {
        System.out.println("NAME SEARCH File IO Exception");
    }

    // Read from the source file, change, and write to target file
    try {
        dataInStream = new BufferedReader( new FileReader
("c:/jdk1.1.4/lib/test.ini"));
        workspace = new StringBuffer(10000);

        // Read from the source file
        try {
            insertString = "USERNAME=" + userStr;
            replaceMarker = "USERNAME=";
            markerLength = replaceMarker.length();
            while (dataInStream.ready()) {
                try {
                    aStr = dataInStream.readLine();
                    locator = aStr.indexOf(replaceMarker);
                    if(locator >= 0) { // Make the replace
                        workspace.append(insertString);
                        found = 1;
                    } else {
                        workspace.append(aStr);
                    }
                    workspace.append('\n');
                }
                catch(IOException ex) {}
            }
            dataInStream.close();

            if(found == 0) { // Make the insert at the end of the file
                workspace.append(insertString);
            }

  // Write to the target file  try {  dataOutStream = new BufferedWriter(
new FileWriter ("c:/jdk1.1.4/lib/test.ini"));  try { 
dataOutStream.write(workspace.toString(),0,workspace.length ()); 
dataOutStream.close();	}  catch(IOException ex) {}  }	catch
(FileNotFoundException ex) {  System.out.println("TARGET File not
found");  }

        }
        catch (IOException ex) {}

    }
    catch (FileNotFoundException ex) {
        System.out.println("SOURCE File not found");
    }

  }
}

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet
Re: NEED TO CONVERT Java to C (a simple file I/O program)
#18
Author: Sox
Date: Sun, 21 Dec 1997 00:00
17 lines
1542 bytes
>/*
> *  Created 12/14/97 by Vikram Adige. PURPOSE: To run during computer
> *  startup, obtain the username from the file config.txt, and insert
> *  it into the orawin.ini file in the "USERNAME=" line.  If the line
> *  does not exist, it must be created.
> */


If these are the only specs, this is maybe a two hour job
for any decent c programmer. I don't recommend asking someone
to convert from java. The details concerning IO are different enough
that it would be faster to rebuild it from the ground up. (my humble
opinion)

-sox
barky@tdl.com
Re: NEED TO CONVERT Java to C (a simple file I/O program)
#19
Author: Yan Vinogradov
Date: Mon, 22 Dec 1997 00:00
6 lines
1369 bytes
MS Java SDK comes with an utility jexegen (executable generator) that
converts java classes (or java source files, don't remember) into exe.  I
tried it once with "hello word" and it worked fine. I also tried it with a
more sophisticated java program that used graphics and it failed (or I
failed).  You can give it  a try, it's free for download also.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads