java i/o

I copied/tweaked some VisAD code for reading/parsing input files.
The boiled down code and input files (included) run fine on my SGI (running
their latest jdk), but give me a java.lang.NumberFormatException on my NT box
(with "Java 2").  See outputs at very end.

Write once, run anywhere?  Any suggestions?

--Randy

//-----------------------------------------------
//  readTest.java
import java.rmi.RemoteException;
import java.io.*;

public class readTest extends Object {
  static int var1 = 0;

  public static void main(String args[])
        throws IOException, RemoteException {

    int nverts = 4;
    float vtx[][] = new float[nverts][3];
    System.out.println("nverts = "+nverts+"\n");

    // Define input stream - vertices file
    InputStreamReader inStr = new InputStreamReader(new
FileInputStream("verts.dat"));

    // Define temporary integer array
    int[] ints = new int[80];

    // convert array of integers to array of characters
    int l = 0;

    System.out.println("Reading verts...\n");
    char[] chars;
    for (int c=0; c<nverts; c++) {
      int idx = -1;
      for (int d=0; d<4; d++) {    // idx,x,y,z
        l = 0;
        try {
          ints[0] = inStr.read();
        }
        catch (Exception e) {
          System.out.println("test: "+e);
        }
        while ( (ints[l] != 32) && (ints[l] != 10) ) {
          try {
            ints[++l] = inStr.read();
          }
          catch (Exception e) {
            System.out.println("test: "+e);
          }
        }
        chars = new char[l];
        for (int i=0; i<l; i++) {
          chars[i] = (char) ints[i];
        }
        if (d==0)
          idx = (Integer.valueOf(new String(chars))).intValue();
//          idx = (Long.valueOf(new String(chars))).longValue();
        else
          vtx[c][d-1] = (Float.valueOf(new String(chars))).floatValue();
      }
      if ((c < 10) || (c > (nverts-10)))
        System.out.println(idx+"="+vtx[c][0]+","+vtx[c][1]+","+vtx[c][2]);
    }

    // do EOF stuff
    try {
      inStr.close();
    }
    catch (Exception e) {
      System.out.println("readTest: "+e);
    }

    //---------------------------------------------------------

    int ncells = 1;
    int hex[][] = new int[ncells][8];
    System.out.println("ncells = "+ncells+"\n");

    // Define input stream - cells file
    inStr = new InputStreamReader(new FileInputStream("cells.dat"));

    System.out.println("Reading hex cells...\n");
    for (int c=0; c<ncells; c++) {
      int idx = -1;
      for (int d=0; d<9; d++) {    // idx,v1,v2,...,v8
        l = 0;
        try {
          ints[0] = inStr.read();
          System.out.println("[0]="+ints[0]);
        }
        catch (Exception e) {
          System.out.println("test: "+e);
        }
        while ( (ints[l] != 32) && (ints[l] != 10) ) {
          try {
            ints[++l] = inStr.read();
            System.out.println(ints[l]);
          }
          catch (Exception e) {
            System.out.println("test: "+e);
          }
        }
        chars = new char[l];
        for (int i=0; i<l; i++) {
          chars[i] = (char) ints[i];
        }
        if (d==0) {
          idx = (Integer.valueOf(new String(chars))).intValue();
          System.out.println("idx= "+idx);
        }
        else {
          hex[c][d-1] = (Integer.valueOf(new String(chars))).intValue();
          System.out.println("hex["+c+"]["+(d-1)+"]= "+hex[c][d-1]);
        }
      }
      if ((c < 10) || (c > (ncells-10)))
        
System.out.println(idx+"="+hex[c][0]+","+hex[c][1]+","+hex[c][2]+","+hex[c][3]+","+hex[c][4]+","+hex[c][5]+","+hex[c][6]+","+hex[c][7]);
    }

    // do EOF stuff
    try {
      inStr.close();
    }
    catch (Exception e) {
      System.out.println("readTest: "+e);
    }

  }
}

---------- verts.dat --------
1 0.0 0.0 0.0
2 1.0 0.0 0.0
3 1.0 1.0 0.0
4 0.0 1.0 0.0

---------- cells.dat ---------
1 1 2 3 4 5 6 7 8

-----> tail of output on SGI
hex[0][5]= 6
[0]=55
32
hex[0][6]= 7
[0]=56
10
hex[0][7]= 8
1=1,2,3,4,5,6,7,8

-----> on NT
hex[0][5]= 6
[0]=55
32
hex[0][6]= 7
[0]=56
13
10
Exception in ...


  • 1998 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: