/**
   * This method reads the contents of a file, and then populates an array with integers inside of
   * it
   *
   * @param inputFile The file being read
   * @param outputArray The array that the numbers will be output to
   */
  public static void readArray(String inputFile, int[] outputArray) {
    boolean flag = false;
    Scanner keyboard = new Scanner(System.in);
    String checkFile = inputFile;
    while (!flag) {

      try {
        DataInputStream inFile = new DataInputStream(new FileInputStream(checkFile));
        for (int i = 0; i < outputArray.length; i++) {
          outputArray[i] = inFile.readInt();
        }
        inFile.close();
        flag = true;
      } catch (EOFException e) {
        System.out.println(e.getMessage());
      } catch (FileNotFoundException e) {
        System.out.println("File not found.");
        System.out.println("Please input the name of the file you'd like to read from: ");
        Scanner checkKeyboard = new Scanner(System.in);
        checkFile = (checkKeyboard.next() + ".dat");
      } catch (IOException e) {
        System.out.println(e.getMessage());
      }
    }
  }
Ejemplo n.º 2
0
 public Tuple getNext() throws NoSuchElementException, TransactionAbortedException {
   try {
     Tuple tuple = new Tuple(td);
     for (int i = 0; i < td.numFields(); i++) {
       IntField intf = IntField.createIntField(in.readInt());
       tuple.setField(i, intf);
     }
     return tuple;
   } catch (EOFException eof) {
     throw new NoSuchElementException(eof.getMessage());
   } catch (Exception e) {
     e.printStackTrace();
     BufferPool.Instance().abortTransaction(tid);
     closeConnection();
     throw new TransactionAbortedException(e);
   }
 }