Article View: comp.lang.java.softwaretools
Article #17NEED TO CONVERT Java to C (a simple file I/O program)
From: adige
Date: Thu, 18 Dec 1997 00:00
Date: Thu, 18 Dec 1997 00:00
109 lines
4840 bytes
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
Technical Details
Message-ID:
<882463462.1363410956@dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,74435d546a2586a1,start X-Google-Attributes: gid10a146,public X-Google-Thread: f6cb0,74435d546a2586a1,start X-Google-Attributes: gidf6cb0,public X-Google-Thread: f5e83,74435d546a2586a1,start X-Google-Attributes: gidf5e83,public X-Google-Thread: 113ae9,74435d546a2586a1,start X-Google-Attributes: gid113ae9,public X-Google-Thread: 1014db,74435d546a2586a1,start X-Google-Attributes: gid1014db,public X-Google-Thread: 10bb9b,74435d546a2586a1,start X-Google-Attributes: gid10bb9b,public From: adige@xnet.com Subject: NEED TO CONVERT Java to C (a simple file I/O program) Date: 1997/12/18 Message-ID: <882463462.1363410956@dejanews.com> X-Deja-AN: 299399371 To: adige@xnet.com X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.0; Windows 95) X-Originating-IP-Addr: 207.25.35.2 (gate2.twi.com) Organization: Deja News Posting Service X-Authenticated-Sender: adige@xnet.com X-Article-Creation-Date: Thu Dec 18 16:44:22 1997 GMT Reply-To: adige@xnet.com Newsgroups: comp.lang.java.softwaretools,cn.bbs.comp.lang.java,comp.lang.java.machine,comp.lang.java.programmer,comp.lang.java.help,comp.lang.c