Writing an integer array to a file...

Okay, so I just wanna write a sorted integer array to file... but I'm having a problem or two.
int[] array = read(new File("C:\\college work\radixsort.txt");
radixSort(array, array.length);That text file is a list of 30 numbers.
After the radixSort method is called the values in the text file are sorted into the correct order. Then I want to write the sorted values to a text file radixSorted.txt
I had too many problems with printArray() so I figured this could be easier.
I have tried FileInputStream and FileWriter but no luck.
I don't want the answer, but just something to help point me in the right direction.
Thank you.

pri.println(char[] x) looks like the one I am looking for.
I have modified the code. I've placed only the println part inside the loop now, but it's just the pri.println(char[], array) now. I'm nearrrrly there! (I think).
try
               PrintWriter pri = new PrintWriter(new FileWriter("C:/college work/radixsort.txt", true));
               for (int h = 0; h < array.length; h++)
                    pri.println(char[], array);
          catch (Exception e)
               e.printStackTrace();
               System.out.println("No such file exists.");
          finally
               pri.close();
          }Edited by: JayJay88 on Nov 8, 2008 1:16 PM

Similar Messages

  • Writing/reading 3 arrays in one file

    hello guys
    i am trying to write 3 different arrays(size 25) in one file and seek to retrieve them independently to generate a comparative graph of performance in a different window, as i m designing a biological simulator.
    please help me here as i m not sure how to write/read them individually in one file.
    thanks a lot in advance
    avi

    Just write them to a sequentual access file and separate them with some sort of special character. Otherwise use random access files because you know the length of the arrays. http://java.sun.com/docs/books/tutorial/essential/io/rafs.html
    I would go with the first because it is the easiest.

  • Writing 2-D array to spreadsheet file changes value of time column when saved

    I have a program that creates a new row in a table each time the loop performs.  Each time the loop performs and a row is added to the table, the program uses the "write to spreadsheet file.vi" to save this new table over the previous table.  The array is also visible on the front panel of the vi.  The program works in such a way that you can stop adding data to the array, start adding data to a new array, then come back to the original by using the "read from spreadsheet file.vi".  My problem comes after opening the spreadsheet file.  The first column of the array, which corresponds to the time when the data in that row was taken, has different values than those that were seen when the array was originally displayed on the front panel.  In fact, all of the rows that were created the last time the program was run with that array have the same value in the time column, while all of the other columns keep their correct values.  Here is an example of what is happening...
    When I start the program, and run it for 5 iterations, I get a table like this displayed on the front panel:
    3241713920
    85.88012
    93.88012
    1.735015...
    3241713930
    85.97603
    93.97603
    1.747003...
    3241713940
    84.58855
    92.58855
    1.573568...
    3241713950
    84.48096
    92.48096
    1.560119...
    3241713960
    84.93667
    92.93667
    1.617084...
    This array is saved to the spreadsheet file with each added row.  If I initialize and build another array, then come back to this first array using "read from spreadsheet file.vi," I will receive the following table:
    3241713920
    85.88012
    93.88012
    1.735015...
    3241713920
    85.97603
    93.97603
    1.747003...
    3241713920
    84.58855
    92.58855
    1.573568...
    3241713920
    84.48096
    92.48096
    1.560119...
    3241713920
    84.93667
    92.93667
    1.617084...
    If anyone could tell me why this is happening and/or how to fix it, that would be greatly appreciated.  One option I have contemplated is just having each individual row appended to the file instead of resaving the entire array with each iteration.  However, I would prefer to do it the way I am currently doing it, so I can pass the array through each time and perform different tasks on it, such as averaging the values in columns over different time periods.  Thank you in advance to anyone who can help. 

    DWDerr wrote:
    If anyone could tell me why this is happening and/or how to fix it, that would be greatly appreciated.  ...
    This KnowledgeBase article may help.  I think things changed in LV8.20, but I could be wrong.
    =====================================================
    Fading out. " ... J. Arthur Rank on gong."

  • Saving an integer array into a .txt file

    hii, im only a beginner in java, so this is the only code i've learned so far for saving array elements into a file
         public static void saveNames(String [] name) throws IOException
                   FileWriter file = new FileWriter("Example\\names.txt");
                   BufferedWriter out = new BufferedWriter(file);
                   int i = 0;
                   while (i < name.length)
                             if (name[i] != null)
                                  out.write(name);
                                  out.newLine();
                                  i++;
                   out.flush();
                   out.close();
    However, this is only used for string arrays; and i can't call the same method for an integer array (because it's not compatible with null)
    I don't really understand this code either... since my teacher actually just gave us the code to use, and didn't really explain how it works
    I have the same problem for my reading a file code as well --> it's only compatible with string
         public static String [] readNames (String [] name) throws IOException
              int x = 0;
              int counter = 0;
              String temp = "asdf";
              name = new String [100];
              FileReader file = new FileReader("Example\\names.txt");
              BufferedReader in = new BufferedReader(file);
              int i = 0;
              while (i < array.length && temp != null)                    // while the end of file is not reached
                   temp = in.readLine();
                   if (temp != null)
                        name[i] = temp;                    // saves temp into the array
                   else
                        name[i] = "";
                   i++;
              in.close();                                   // close the file
              return name;
    Could someone suggest a way to save elements from an integer array to a file, and read integer elements of that file?
    Or if it's possible, replace null with a similar variable (function?), that is suitable for the integer array (i can't use temp != 0 because some of my elements might be 0)
    Thanks so much!!!!!

    because it's not compatible with nullI think it should be okay to just remove the null condition check since there are no null elements in a primitive array when writing.
    Use Integer.parseInt() [http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] to convert the String into an Integer when you read it back and use Integer.toString() to be able to write it as a String.

  • Writing int [ ] Array in a file

    Hye
    Can you tell me which Stream I can use to write an Integer Array (defined as int [ 7000]) in a file .txt
    I want to write as a whole not one by one.
    Thanks

    import java.util.Vector;
    import java.io.*;
    public class Queue extends Vector {
      ** FIFO, first in first out
      Queue() {
      super();
    void put(Object o) {
      addElement(o);
    Object get() {
      if (isEmpty()) return null;
        Object o = firstElement();
        removeElement(o);
        return o;
    Object peek() {
      if (isEmpty()) return null;
        return firstElement();
    To serialize (save the Queue state to a file) :
    public static void main(String args[]) {
      Queue theQueue;
      theQueue = new Queue();
      theQueue.put(new int[]{1, 2, 3, 4});
      theQueue.put("ABCDE");
      theQueue.put(new Integer(3));
      System.out.println(theQueue.toString());
      // serialize the Queue
      System.out.println("serializing theQueue");
      try {
          FileOutputStream fout = new FileOutputStream("thequeue.dat");
          ObjectOutputStream oos = new ObjectOutputStream(fout);
          oos.writeObject(theQueue);
          oos.close();
       catch (Exception e) { e.printStackTrace(); }
    To unserialize (to load a previously saved Queue) :
    public static void main(String args[]) {
       Queue theQueue;
       theQueue = new Queue();
       // unserialize the Queue
       System.out.println("unserializing theQueue");
       try {
        FileInputStream fin = new FileInputStream("thequeue.dat");
        ObjectInputStream ois = new ObjectInputStream(fin);
        theQueue = (Queue) ois.readObject();
        ois.close();
       catch (Exception e) { e.printStackTrace(); }
       System.out.println(theQueue.toString());    
    }hope that helps

  • Writing data from array to file

    May i know how to write string from a array into a file.
    I have use string tokenizer to extract every line from a file using readline and use stringtokenizer to spilt the line using tab delimiter for processing.
    But if i want to write data from array to file with tab as a delimiter and how to go to the next line. How do i do that. Below is the task and i have state a simple example on a array i have and the file output that i want.
    Pls advice.. Thanks
    eg of a array
    array[0] = Data
    array[1] = One
    array[2] = Data
    array[3] = Two
    array[4] = Final
    array[5] = Data
    From the above array, i want to write to a file so that it will appear something as below
    Eg textfile.txt
    Data One
    Data Two
    Final Data
    PLs attached a simple code as a example as i am only begining to start useing the IO feature in java. Thanks

    Really thanks for your help,
    but u are mentioning that i have already know the number of countters in advance , that is to say the 2 * counters.
    But is there a way to solve this problem which i mean if i dun know the number of predefined counters. Maybe i should say, there is more than 2 counters and in another situation, the counters will only be defined during runtime. Actually the solution u give will work nicely with 2 counters. but wat if the counter is more than 4, i wll have to concatenate the string a lot of time. so is there any solution around this problem. That why i am wandering if tere is any solution to write to the file when the counters can be only determined in runtime
    Pls advice on the above with a code samples if possible.

  • Problem with ArrayLists and writing and reading from a .dat file (I think)

    I'm brand new to this forum, but I'm sure hoping someone can help me with a problem I'm having with ArrayLists. This program was originally created with an array of objects that were displayed on a GUI with jtextFields, then cycling thru them via jButtons: First, Next, Previous, Last. Now I need to add the ability to modify, delete and add records. Both iterations of this program needed to write to and read from a .dat file.
    It worked just like it was suppose to when I used just the array, but now I need to use a "dynamic array" that will grow or shrink as needed: i.e. an ArrayList.
    When I aded the ArrayList I had the ArrayList use toArray() to fill my original array so I could continue to use all the methods I'd created for using with my array. Now I'm getting a nullPointerException every time I try to run my program, which means somewhere I'm NOT filling my array ???? But, I'm writing just fine to my .dat file, which is confusing me to no end!
    It's a long program, and I apologize for the length, but here it is. There are also 2 class files, a parent and 1 child below Inventory6. This was written in NetBeans IDE 5.5.1.
    Thank you in advance for any help anyone can give me!
    LabyBC
    package my.Inventory6;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import java.io.*;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.lang.IllegalStateException;
    import java.util.NoSuchElementException;
    import java.util.ArrayList;
    import java.text.NumberFormat;
    // Class Inventory6
    public class Inventory6 extends javax.swing.JFrame {
    private static InventoryPlusColor[] inventory;
    private static ArrayList inList;
    // create a tool that insure the specified format for a double number, when displayed
    private DecimalFormat doubleFormat = new DecimalFormat( "0.00" );
    private DecimalFormat singleFormat = new DecimalFormat( "0");
    // the index within the array of products of the current displayed product
    private int currentProductIndex;
    /** Creates new form Inventory6 */
    public Inventory6() {
    initComponents();
    currentProductIndex = 0;
    } // end Inventory6()
    private static InventoryPlusColor[] getInventory() {
    ArrayList<InventoryPlusColor> inList = new ArrayList<InventoryPlusColor>();
    inList.add(new InventoryPlusColor(1, "Couch", 3, 1250.00, "Blue"));
    inList.add(new InventoryPlusColor(2, "Recliner", 10, 525.00, "Green"));
    inList.add(new InventoryPlusColor(3, "Chair", 6, 125.00, "Mahogany"));
    inList.add(new InventoryPlusColor(4, "Pedestal Table", 2, 4598.00, "Oak"));
    inList.add(new InventoryPlusColor(5, "Sleeper Sofa", 4, 850.00, "Yellow"));
    inList.add(new InventoryPlusColor(6, "Rocking Chair", 2, 459.00, "Tweed"));
    inList.add(new InventoryPlusColor(7, "Couch", 4, 990.00, "Red"));
    inList.add(new InventoryPlusColor(8, "Chair", 12, 54.00, "Pine"));
    inList.add(new InventoryPlusColor(9, "Ottoman", 3, 110.00, "Black"));
    inList.add(new InventoryPlusColor(10, "Chest of Drawers", 5, 598.00, "White"));
    for (int j = 0; j < inList.size(); j++)
    System.out.println(inList);
    InventoryPlusColor[] inventory = (InventoryPlusColor[]) inList.toArray
    (new InventoryPlusColor[inList.size()]);
    return inventory;
    } // end getInventory() method
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    IDNumberLbl = new javax.swing.JLabel();
    IDNumberField = new javax.swing.JTextField();
    prodNameLbl = new javax.swing.JLabel();
    prodNameField = new javax.swing.JTextField();
    colorLbl = new javax.swing.JLabel();
    colorField = new javax.swing.JTextField();
    unitsInStockLbl = new javax.swing.JLabel();
    unitsInStockField = new javax.swing.JTextField();
    unitPriceLbl = new javax.swing.JLabel();
    unitPriceField = new javax.swing.JTextField();
    invenValueLbl = new javax.swing.JLabel();
    invenValueField = new javax.swing.JTextField();
    restockingFeeLbl = new javax.swing.JLabel();
    restockingFeeField = new javax.swing.JTextField();
    jbtFirst = new javax.swing.JButton();
    jbtNext = new javax.swing.JButton();
    jbtPrevious = new javax.swing.JButton();
    jbtLast = new javax.swing.JButton();
    jbtAdd = new javax.swing.JButton();
    jbtDelete = new javax.swing.JButton();
    jbtModify = new javax.swing.JButton();
    jbtSave = new javax.swing.JButton();
    jPanel2 = new javax.swing.JPanel();
    searchIDNumLbl = new javax.swing.JLabel();
    searchIDNumbField = new javax.swing.JTextField();
    jbtSearch = new javax.swing.JButton();
    searchResults = new javax.swing.JLabel();
    jbtExit = new javax.swing.JButton();
    jbtExitwoSave = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Inventory Program"));
    IDNumberLbl.setText("ID Number");
    IDNumberField.setEditable(false);
    prodNameLbl.setText("Product Name");
    prodNameField.setEditable(false);
    colorLbl.setText("Product Color");
    colorField.setEditable(false);
    colorField.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    colorFieldActionPerformed(evt);
    unitsInStockLbl.setText("Units In Stock");
    unitsInStockField.setEditable(false);
    unitPriceLbl.setText("Unit Price $");
    unitPriceField.setEditable(false);
    invenValueLbl.setText("Inventory Value $");
    invenValueField.setEditable(false);
    restockingFeeLbl.setText("5% Restocking Fee $");
    restockingFeeField.setEditable(false);
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(unitPriceLbl)
    .addComponent(unitsInStockLbl)
    .addComponent(colorLbl)
    .addComponent(prodNameLbl)
    .addComponent(IDNumberLbl)
    .addComponent(restockingFeeLbl)
    .addComponent(invenValueLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(IDNumberField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(prodNameField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(colorField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(unitsInStockField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(unitPriceField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(restockingFeeField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(invenValueField, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))
    .addContainerGap())
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(IDNumberLbl)
    .addComponent(IDNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(prodNameLbl)
    .addComponent(prodNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(colorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(colorLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(unitsInStockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(unitsInStockLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(unitPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(unitPriceLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(restockingFeeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(restockingFeeLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(invenValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(invenValueLbl))
    .addContainerGap())
    jbtFirst.setText("First");
    jbtFirst.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtFirstActionPerformed(evt);
    jbtNext.setText("Next");
    jbtNext.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtNextActionPerformed(evt);
    jbtPrevious.setText("Previous");
    jbtPrevious.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtPreviousActionPerformed(evt);
    jbtLast.setText("Last");
    jbtLast.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtLastActionPerformed(evt);
    jbtAdd.setText("Add");
    jbtAdd.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtAddActionPerformed(evt);
    jbtDelete.setText("Delete");
    jbtModify.setText("Modify");
    jbtModify.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtModifyActionPerformed(evt);
    jbtSave.setText("Save");
    jbtSave.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtSaveActionPerformed(evt);
    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Search by:"));
    searchIDNumLbl.setText("Item Number:");
    jbtSearch.setText("Search");
    searchResults.setFont(new java.awt.Font("Tahoma", 1, 12));
    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(searchIDNumLbl)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGap(259, 259, 259)
    .addComponent(searchResults, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jbtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(searchIDNumbField, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(searchIDNumLbl)
    .addComponent(searchIDNumbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGap(32, 32, 32)
    .addComponent(searchResults, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtSearch)))
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    jbtExit.setText("Save and Exit");
    jbtExit.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtExitActionPerformed(evt);
    jbtExitwoSave.setText("Exit");
    jbtExitwoSave.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtExitwoSaveActionPerformed(evt);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
    .addComponent(jbtExitwoSave, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jbtExit)))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jbtFirst)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtNext)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtPrevious)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtLast))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addGap(12, 12, 12)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jbtAdd)
    .addComponent(jbtDelete)
    .addComponent(jbtModify)
    .addComponent(jbtSave))))
    .addContainerGap())
    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtFirst, jbtLast, jbtNext, jbtPrevious});
    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtAdd, jbtDelete, jbtModify, jbtSave});
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(21, 21, 21)
    .addComponent(jbtAdd)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtDelete)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtModify)
    .addGap(39, 39, 39)
    .addComponent(jbtSave))
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jbtFirst)
    .addComponent(jbtNext)
    .addComponent(jbtPrevious)
    .addComponent(jbtLast))
    .addGap(15, 15, 15)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jbtExit)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtExitwoSave)))
    .addContainerGap())
    pack();
    }// </editor-fold>
    private void jbtExitwoSaveActionPerformed(java.awt.event.ActionEvent evt) {                                             
    System.exit(0);
    private void jbtSaveActionPerformed(java.awt.event.ActionEvent evt) {                                       
    String prodNameMod, colorMod;
    double unitsInStockMod, unitPriceMod;
    int idNumMod;
    idNumMod = Integer.parseInt(IDNumberField.getText());
    prodNameMod = prodNameField.getText();
    unitsInStockMod = Double.parseDouble(unitsInStockField.getText());
    unitPriceMod = Double.parseDouble(unitPriceField.getText());
    colorMod = colorField.getText();
    if(currentProductIndex == inventory.length) {
    inList.add(new InventoryPlusColor(idNumMod, prodNameMod,
    unitsInStockMod, unitPriceMod, colorMod));
    InventoryPlusColor[] inventory = (InventoryPlusColor[]) inList.toArray
    (new InventoryPlusColor[inList.size()]);
    } else {
    inventory[currentProductIndex].setIDNumber(idNumMod);
    inventory[currentProductIndex].setProdName(prodNameMod);
    inventory[currentProductIndex].setUnitsInStock(unitsInStockMod);
    inventory[currentProductIndex].setUnitPrice(unitPriceMod);
    inventory[currentProductIndex].setColor(colorMod);
    displayProduct(inventory[currentProductIndex]);
    private static void writeInventory(InventoryPlusColor i,
    DataOutputStream out) {
    try {
    out.writeInt(i.getIDNumber());
    out.writeUTF(i.getProdName());
    out.writeDouble(i.getUnitsInStock());
    out.writeDouble(i.getUnitPrice());
    out.writeUTF(i.getColor());
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Exception writing data",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } //end writeInventory()
    private static DataOutputStream openOutputStream(String name) {
    DataOutputStream out = null;
    try {
    File file = new File(name);
    out =
    new DataOutputStream(
    new BufferedOutputStream(
    new FileOutputStream(file)));
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Error", "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    return out;
    } // end openOutputStream()
    private static void closeFile(DataOutputStream out) {
    try {
    out.close();
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Exception closing file",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } // end closeFile()
    private static DataInputStream getStream(String name) {
    DataInputStream in = null;
    try {
    File file = new File(name);
    in = new DataInputStream(
    new BufferedInputStream(
    new FileInputStream(file)));
    } catch (FileNotFoundException e) {
    JOptionPane.showMessageDialog(null, "The file doesn't exist",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Error creating file",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    return in;
    private static void closeInputFile(DataInputStream in) {
    try {
    in.close();
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Exception closing file",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } // end closeInputFile()
    private double entireInventory() {
    // a temporary double variable that the method will return ...
    // after each product's inventory is added to it
    double entireInventory = 0;
    // loop to control number of products
    for (int index = 0; index < inventory.length; index++) {
    // add each inventory to the entire inventory
    entireInventory += inventory[index].setInventoryValue();
    } // end loop to control number of products
    return entireInventory;
    } // end method entireInventory
    private void jbtLastActionPerformed(java.awt.event.ActionEvent evt) {                                       
    currentProductIndex = inventory.length-1; // move to the last product
    // display the information for the last product
    displayProduct(inventory[currentProductIndex]);
    private void jbtPreviousActionPerformed(java.awt.event.ActionEvent evt) {                                           
    if (currentProductIndex != 0) // it's not the first product displayed
    currentProductIndex -- ; // move to the previous product (decrement the current index)
    } else // the first product is displayed
    currentProductIndex = inventory.length-1; // move to the last product
    // after the current product index is set, display the information for that product
    displayProduct(inventory[currentProductIndex]);
    private void jbtNextActionPerformed(java.awt.event.ActionEvent evt) {                                       
    if (currentProductIndex != inventory.length-1) // it's not the last product displayed
    currentProductIndex ++ ; // move to the next product (increment the current index)
    } else // the last product is displayed
    currentProductIndex = 0; // move to the first product
    // after the current product index is set, display the information for that product
    displayProduct(inventory[currentProductIndex]);
    private void jbtFirstActionPerformed(java.awt.event.ActionEvent evt) {                                        
    currentProductIndex = 0;
    // display the information for the first product
    displayProduct(inventory[currentProductIndex]);
    private void colorFieldActionPerformed(java.awt.event.ActionEvent evt) {                                          
    // TODO add your handling code here:
    private void jbtModifyActionPerformed(java.awt.event.ActionEvent evt) {                                         
    prodNameField.setEditable(true);
    prodNameField.setFocusable(true);
    unitsInStockField.setEditable(true);
    unitPriceField.setEditable(true);
    private void jbtAddActionPerformed(java.awt.event.ActionEvent evt) {                                      
    IDNumberField.setText("");
    IDNumberField.setEditable(true);
    prodNameField.setText("");
    prodNameField.setEditable(true);
    colorField.setText("");
    colorField.setEditable(true);
    unitsInStockField.setText("");
    unitsInStockField.setEditable(true);
    unitPriceField.setText("");
    unitPriceField.setEditable(true);
    restockingFeeField.setText("");
    invenValueField.setText("");
    currentProductIndex = inventory.length;
    private void jbtExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
    DataOutputStream out = openOutputStream("inventory.dat");
    for (InventoryPlusColor i : inventory)
    writeInventory(i, out);
    closeFile(out);
    System.exit(0);
    private static InventoryPlusColor readProduct(DataInputStream in) {
    int idNum = 0;
    String prodName = "";
    double inStock = 0.0;
    double pric

    BalusC -- The line that gives me my NullPointerException is when I call the "DisplayProduct()" method. Its a dumb question, but with NetBeans how do I find out which reference could be null? I'm not very familiar with how NetBeans works with finding out how to debug. Any help you can give me would be greatly appreciated.The IDE is com-plete-ly irrelevant. It's all about the source code.
    Do you understand anyway when and why a NullPointerException is been thrown? It is a subclass of RuntimeException and those kind of exceptions are very trival and generally indicate an design/logic/thinking fault in your code.
    SomeObject someObject = null; // The someObject reference is null.
    someObject.doSomething(); // Invoking a reference which is null would throw NPE.

  • How to load and display a byte array (jpeg) image file dynamically in Flex?

    My web service client (servlet) received a binary jpeg data from an Image Server. The Flex application invokes the
    servlet via HttpService and receives the binary jpeg data as byte array.  How could it be displayed dynamically
    without writing the byte array to a jpeg file?  Please help (some sample code is very much appreciated).

    JPEGEncoder is only useful for converting BitmapData to ByteArray, not the other way around.
    By the way JPEGEncoder and PNGEncoder are part of the Flex SDK now, so no need to use AS3Lib (alltough it's a good library to have around).
    To display/use a ByteArray as image, use a Loader instance with the loadBytes method.
        Loader.loadBytes(bytes:ByteArray, context:LoaderContext = null);
    Listen for the complete event on the Loader.contentLoaderInfo and get the BitmapData in the event handler.
    private function loadJpeg():void {
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
        //jpgBA is the ByteArray loaded from webservice
        loader.loadBytes(jpgBA);
    private function loaderCompleteHandler(evt:Event):void {
        var t:LoaderInfo = evt.currentTarget as LoaderInfo;
        // display the jpeg in an Image component
        img.source = t.content;
    <mx:Image id="img" scaleContent="false" />

  • Trouble writing to object array

    Hi I did a semester of java 2 years ago and I'm trying to remember what I knew so please bear with me...
    I am extracting data from an xml file and then writing that information to an object array called files containing 4 string and 1 array. This files array is in turn an element in another object array containing 400 files arrays called records.
    It appeared to be working but when I want it to print out which ever record I have selected it only prints out the last record! It seems to be overwriting each files array with the next?
    Another problem I can only print out an element of the array not the entire thing?
    Please help have spent weeks on this
    Here is the code:
    Object[] Records = new Object[400];
    Object files[] = new Object[5];
    NodeList records = doc.getElementsByTagName("record");
    for( int i = 0; i < records.getLength();i++)
    Element record = (Element) records.item(i);
    NodeList headers = record.getElementsByTagName("header");
    Element header = (Element) headers.item(0);
    NodeList ids = header.getElementsByTagName("identifier");
    for(int j = 0; j < ids.getLength(); j++){
    Element id = (Element) ids.item(j);
    String ID = getText(id);
    files[0] = ID;
    NodeList metadatas = record.getElementsByTagName("metadata");
    Element metadata = (Element) metadatas.item(0);
    NodeList citeseers = metadata.getElementsByTagName("oai_citeseer:oai_citeseer");
    Element citeseer = (Element) citeseers.item(0);
    NodeList titles = citeseer.getElementsByTagName("dc:title");
    for(int k = 0; k < titles.getLength(); k++){
    Element title = (Element) titles.item(k);
    String TITLE = getText(title);
    files[1] = TITLE;
    NodeList subjects = citeseer.getElementsByTagName("dc:subject");
    for(int m = 0; m < subjects.getLength(); m++){
    Element subject = (Element) subjects.item(m);
    String SUBJECT = getText(subject);
    files[2] = SUBJECT;
    NodeList descriptions = citeseer.getElementsByTagName("dc:description");
    for(int n = 0; n < descriptions.getLength(); n++){
    Element description = (Element) descriptions.item(n);
    String DESCRIPTION = getText(description);
    files[3] = DESCRIPTION;
    String[] Names = new String[20];
    NodeList authors = citeseer.getElementsByTagName("oai_citeseer:author");
    for(int l = 0; l < authors.getLength(); l++){
    Element author = (Element) authors.item(l);
    Names[l] = author.getAttribute("name");
    files[4] = Names;
    System.out.println("The id is "+files[0]);
    System.out.println("The title is "+ files[1]);
    System.out.println("The Subject is "+ files[2]);
    System.out.println("The Description is "+ files[3]);
    for(int q=0; q < authors.getLength(); q++){
    System.out.println("The Names are "+ ((String[])files[4])[q]);
    //Records[i] = files;
    System.out.println(((Object[])Records[0])[0]);

    I'm afraid I'm not going to make you a millionaire but I feel so relieved at the moment that if I had a million I'd give it to you!!Yeah, I know you won't make me a millionaire, but I can dream... :)
    thanks for all your helpYou are welcome. Do you understand why you needed to move the creation of the "files" array.

  • Multiple writes of a DBL 2D array to binary file

    Hello.
    Does anyone have an example of writing a 2D array to a binary file multiple times?
    Specifically, I need to write a 2D array of DBL to a binary file mulitple times and then (later) be able to read it back (reconvert to DBL). All of the examples that I've found only do one write and then close the file. I need to leave the file reference open and write data to it over the period of a few days. The data comes out of a queue that is fed from a DAQ loop. (In an acquistion loop I feed a queue and in a slower loop I dequeue the data and write it to disk)
    I believe it has something to do with the pos mode and offset mode but I can't figure it.
    I haven't been able to successfully read the data back yet from the .bin file so I'm not sure if I'm even writing it correctly.
    The closest example that I've found is the High Speed Data Logger and High Speed Data Reader but I haven't had any luck with those.
    Thanks in advance.
    Steve
    LabVIEW 7.1
    Solved!
    Go to Solution.

    To change the representation of a number, use the Numeric > Conversion sub-palette.
    The example below shows that the wires contain the representation info independently of the destination indicators : you can connect different types of numerics to the same wire and LabVIEW will automatically adapt to the type (the coercion dots indicate that a convertion has been done). Everything you should want to know about converting numbers is explained in the LabVIEW Help : "Conversion VIs and Functions"
    Message Edited by chilly charly on 07-30-2005 10:57 AM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Convert to single.png ‏27 KB

  • Saving An Object Array to a File

    Please Help,
    I am fairly new to Java. I am trying to write a program that inputs merchandise information (ItemName, Description, Price, etc�) to an object array. The program works internally with the array perfectly, but I can�t get it to save the array to a file so it can be read and reused the next time the program is run. The class the array is built on implements Serializable, but when it tries to save it to a file, it throws an exception message saying that my object is not serializable.
    Does anyone have some code to help me save information to an array (so it can be used within the program), save the array to a disk file, and read the file back into the program the next time the program opens?
    Thank you,
    Bob

    Thank you for your help. The total code is quite lengthy so I�ve tried to pick the most relevant code to include here.
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.text.*;
    import java.io.*;
    public class Class1 extends WindowAdapter implements ActionListener
    // Object Array Declaration.
    ItemInfo ItemArray[] = new ItemInfo[100];
    * This is the Inner Class that the Array is built on. I have two constructors in it because I
    * tried several different methods to make this write to the disk file
    public class ItemInfo implements Serializable
         int ItemNum;
         int DeptNum;
         String ItemName;
         String Model;
         String Description;
         float Price;
         int Units;
    // Constructors
         public ItemInfo() {};
         public ItemInfo(int inItemNum, int inDeptNum, String
                             inItemName, String inModel, String
                             inDescription, float inPrice, int inUnits)
              ItemNum = inItemNum;
              DeptNum = inDeptNum;
              ItemName = inItemName;
              Model = inModel;
              Description = inDescription;
              Price = inPrice;
              Units = inUnits;
    } // end class ItemInfo.
    * openOutputStream() *
         private void openOutputStream()
              try
              // create file and output object streams
                   outputItemFile = new FileOutputStream("A:ItemFile.txt");
                   objSaveItems = new ObjectOutputStream(outputItemFile);
              } // end try
              catch (Exception error)
                   System.err.println("Error opening file");
              } // end catch
         } // end openOutputStream().
    * closeOutputStream() *
         private void closeOutputStream()
              try
                   objSaveItems.close();
                   outputItemFile.close();
              catch (IOException error)
                   System.err.println("Error Closing File");
              } // end catch
         } // end closeOutputStream().
    * AddToItemArray() - This method just assigns the information to the Array elements *
         private void AddToItemArray()
              int ArrayNum = intItemFileSize - 1;
              ItemArray[ArrayNum] = new ItemInfo();
              ItemArray[ArrayNum].ItemNum = intNewItemNum;
              ItemArray[ArrayNum].DeptNum = intDeptNum;
              ItemArray[ArrayNum].ItemName = strItemName;
              ItemArray[ArrayNum].Model = strModel;
              ItemArray[ArrayNum].Description = strDescription;
              ItemArray[ArrayNum].Price = fltPrice;
              ItemArray[ArrayNum].Units = intUnits;
         } // end AddToItemArray().
    * WriteToFile() - This is the latest effort to write to the file. The file gets opened, and
    * the first element gets printed, but after that nothing but error messages (printed * below).
         private void WriteToFile()
              try
                   openOutputStream();
                   for (int a = 0; a <= intItemFileSize; a++)
                        objSaveItems.writeObject(ItemArray[a]);
                        objSaveItems.flush();
                   closeOutputStream();
              } // end try.
              catch (Exception error)
                   System.err.println("Error writing to file");
         } // end WriteToFile().
    This is what appears on the disk file after I run the program (three items entered):
    � sr Class1$ItemInfo�&q����B I DeptNumI ItemNumF PriceI UnitsL
    Descriptiont Ljava/lang/String;L ItemNamet Ljava/lang/String;L Modelt Ljava/lang/String;L this$0t LClass1;xp A��� t
    Claw Hammert Hammert CL550{sr  java.io.NotSerializableException(Vx �� 5   xr  java.io.ObjectStreamExceptiond��k�9��   xr  java.io.IOExceptionl�sde%��   xr  java.lang.Exception��> ; �   xr  java.lang.Throwable��5'9w��   L
    detailMessaget  Ljava/lang/String;xpt  Class1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 2 parts: 1) integer array to string 2) string out to a jTextField

    I am completely new to Java and Netbeans, but I'm writing my 1st
    application that takes a "hex" character input from a jTextField,
    then converts it to an "binary" integer array. I then do a lot of bit
    manipulation, and generate a new "binary" integer array.
    String myhex = jTextField1.getText();
        int len = myhex.length();
        int[] binarray = new int[len*4];
            for (int i = 0; i < len; i++) {
               if (myhex.charAt(i) == '0'){
                  binarray[4*i]=0;
                  binarray[4*i+1]=0;
                  binarray[4*i+2]=0;
                  binarray[4*i+3]=0;
               else if (myhex.charAt(i) ==
               // repeat for '1 to 9' and 'a-f/A-F'
               // generate new integer array(s) using various bits from binarrayI realize it might not be the best way to do the
    conversion, but my input can be of arbitrary length,
    and it is my first time trying to write Java code.
    All of the above I've completed and it works...(thanks Netbeans
    for making the gui interface design a real breeze!)
    So I end up with:
    binarray[0]=0 or 1
    binarray[1]=0 or 1
    binarray[2]=0 or 1
    binarray[n]=0 or 1
    Where n can be any number from 0 to 63...
    I then manipulate the bits in binarray creating a new integer array
    and for the sake of expediency let's call it "newbinarray".
    newbinarray[0]=0 or 1
    newbinarray[1]=0 or 1
    newbinarray[2]=0 or 1
    newbinarray[n]=0 or 1
    Where n can be any number from 0 to 63...
    I first need to know how to convert this "newbinarray" integer array to a string.
    In the simplest terms if the first three elements of the array are [0][1][1],
    I want the string to be 011.
    Then I want to take this newly formed string and output it to a jTextField.
    string 011 output in JTextField as 011
    I've scoured the net, and I've seen a lot of complex answers involving
    formatting, but I'm looking for just a simple answer here so I can finish
    this application as quickly as possible.
    Thanks,
    Thorne Kontos

    Here's an example, not using NetBeans:
    import javax.swing.*;
    public class TextDemo extends JPanel
        public TextDemo()
            int[] newbinarray = {0, 1, 1};
            StringBuffer sb = new StringBuffer();
            for (int value : newbinarray)
                sb.append(value);
            String st = new String(sb);
            this.add(new JTextField(st));
        private static void createAndShowGUI()
            JFrame frame = new JFrame("TextDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new TextDemo());
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
    }

  • How to retrieve arrays from a file.

    If i were to save 5 arrays to a file like this.....
    DataOutputStream output;
         DataInputStream input;
         Date today = new Date();
         String filename = "phonebook";
    private String name[] = {""};
         private String surname[] = {""};
         private String home[] = {""};
         private String work[] = {""};
         private String cell[] = {""};
         try
                   output = new DataOutputStream(new FileOutputStream(filename));
              catch(IOException io)
                   JOptionPane.showMessageDialog(null,"This program could not create a storage location. Please check the disk drive and the tun the program again.","Error",JOptionPane.ERROR_MESSAGE);
                   System.exit(1);
    public void save()
              try
                   for(int i=0; i < name.length; i++)
                        output.writeUTF(name);
                        output.writeUTF(surname[i]);
                        output.writeUTF(work[i]);
                        output.writeUTF(home[i]);
                        output.writeUTF(cell[i]);
                   JOptionPane.showMessageDialog(null,"Data succesfully saved to file.","Information message",JOptionPane.INFORMATION_MESSAGE);
              catch(IOException io)
                   System.exit(1);
         }And then I want to use them again on my startup. How would I go about initialising them back into thier origianl arrays. What i mean is I want the arrays to contain theier previous saved values. Is this possible.
    I tried to do it like this but it wont work. I get no errors. It just wont return and strings at all.try
                   input = new DataInputStream(new FileInputStream(filename));
              catch(IOException io)
                   JOptionPane.showMessageDialog(null,"Could not find the correct file to read data from.","Error",JOptionPane.ERROR_MESSAGE);
              try
                   for(int i=0; i< name.length; i++)
                        name[i]=input.readUTF();
                        surname[i]=input.readUTF();
                        work[i]=input.readUTF();
                        home[i]=input.readUTF();
              cell[i]=input.readUTF();
              catch(IOException io)
              }Or is it better to create a seperate file for each array?
    Edited by: Yucca on Mar 23, 2008 2:24 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Any help here please.
    Edited by: Yucca on Mar 23, 2008 6:34 PM

  • Code for how to read an integer array from the command prompt...

    hello,
    Could anyone give me the code for how to read an integer array from the command prompt...its very urgent!..

    If you are using a recent version of Java (5 or later) you can use Scanner:
    http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
    That page has some example code on it, too.

  • Write Text Data Array to text file

    Greetings all. I hope someone can help me as I am really under the gun. The attached vi shows the basics of what I am trying to do. I have already written a vi that takes the Cal Data Array and prints it out in a nicely formatted report. My problem is that the powers that be also want the data saved to a generic text file that can be copied and printed out anywhere they like. As such, I need to save the data to a generic text file in column format such that it will all fit on one page in landscape mode. There are a total of 12 columns of data. I have been trying to create something that would format each column to a specific length instead of them all being the same. No luck so far. Basically, I need columns 1,2,3,8 and 12 to be length of 5. The rest a length of 9. I have tried to place the formatting part in a for loop with the formatting in a case, but it does not appear to work. I really need this quick so if anyone has any ideas, please help. As always, I really appreciate the assistance.
    Thanks,
    Frank
    Attachments:
    Write Cal Data to Text File.vi ‏21 KB

    pincpanter's is a good solution. Beat me to it while I was away building an example. Similiar approach using two for loops and case statement. Here is my suggestion anyway....
    cheers
    David
    Message Edited by David Crawford on 11-23-2005 09:37 AM
    Attachments:
    Write Text Data Array to text file.vi ‏31 KB

Maybe you are looking for

  • Automatic Mail not getting generated through background job

    Hi Experts, We have set up a job variant with spool recipients. We are getting the automatic mail if the job is getting finished successfully. But we are not getting the automatic mail if the job is in cancelled status. Earlier we used to get the mai

  • Can you use your iMac 27" as an external Monitor for a PC?

    After doing a bunch of research I figured it's not possible to do on models later then 2010, BUT I came across a few motherboards (Asus Z87-DELUXE) that have thunderbolt capability and obviously before I go out and spend $400 I'd like to know if it's

  • Acer Monitor X193W aspect ratio

    I just connected our monitor to our new desktop PC running Windows XP Pro. I've loaded CorelDraw 12. However, when working in CorelDraw 12, the page indicated in the Corel workspace looks square as opposed to a vertical retangle proportional to a she

  • Time zone in iWeb blogs

    I could use a little help ... I am publishing an iWeb '09 blog on my website, but the time indicated on my blog entries is 3 hours off. I live on the East Coast, but it appears that the time used for the blogs is West Coast time. Note that I am not u

  • Microphone dont work on flash player

    it works on IE, but not mozilla, or any other browser. can anyone figure this out?