How to Store something in a text file.

Store the record of the session in a text file.
please can any one tell me how can i create this thing.
i cerate the button but does not work correctly and i can not save any calculation/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.Math.*;
import java.math.BigInteger;
public class Calculator2 extends JFrame implements ActionListener{
JLabel lN1, lN2,lN3;//here are the Label.
JTextField tN1, tN2;// here the place for the text field.
JButton btnAdd,btnSub,btnMul,btnDiv,btnClear,btnSave; JTextArea outArea;//all our Button which are in the program.
Calculator2(){//constructor.
Box box=Box.createVerticalBox();//creation of the box.
// input
lN1=new JLabel("Write first number"); box.add(lN1);//creation of the input,the number which we want use.
tN1=new JTextField(100); tN1.setEditable(true); box.add(tN1);//allows or prevents the user editing the text
lN2=new JLabel("write second number"); box.add(lN2);
tN2=new JTextField(100); tN2.setEditable(true); box.add(tN2);
// buttons
btnAdd=new JButton("+"); btnAdd.addActionListener(this); box.add(btnAdd);// button of addition operation
// setPreferredSize();
btnSub=new JButton("-"); btnSub.addActionListener(this); box.add(btnSub);// button of subtraction operation
btnMul=new JButton("*"); btnMul.addActionListener(this); box.add(btnMul);// button of multiplication operation
btnDiv=new JButton("/"); btnDiv.addActionListener(this); box.add(btnDiv);// button of division operation
btnClear=new JButton("Clear"); btnClear.addActionListener(this); box.add(btnClear);// button of Clear operation
btnSave=new JButton("Save"); btnSave.addActionListener(this); box.add(btnSave);// button of save operation
// Output
String desc="This is a simple integer calculator\n";//here the out put with text area.
outArea=new JTextArea(desc,30,60);//out put area with the hight and length.
ScrollPane scrollPane=new ScrollPane();//Creates an empty (no viewport view) JScrollPane where both horizontal and vertical scrollbars appear when needed
scrollPane.add(outArea);
box.add(scrollPane);
Container c=getContentPane();
c.add(box);
c.setBackground(Color.green);//back ground color.
setTitle("Calculator");//title
setSize(600,375);//size
setVisible(true);// visiblity of the program.
private void showStatus(String status) {
lN3.setText(status);
public void actionPerformed(ActionEvent actionEvent){
if(actionEvent.getSource()==btnClear){
outArea.selectAll(); outArea.cut();
} else {
String sN1=tN1.getText(), sN2=tN2.getText(), sOp="";
BigInteger bN1=new BigInteger(sN1);
BigInteger bN2=new BigInteger(sN2);
BigInteger bRes=BigInteger.ZERO, bResDiv[]={BigInteger.ZERO,BigInteger.ZERO};
BigInteger bRemainder=BigInteger.ZERO;
if(actionEvent.getSource()==btnAdd){bRes=bN1.add(bN2); sOp=" + ";}
if(actionEvent.getSource()==btnSub){bRes=bN1.subtract(bN2); sOp=" - ";}
if(actionEvent.getSource()==btnMul){bRes=bN1.multiply(bN2); sOp=" * ";}
if(actionEvent.getSource()==btnDiv){sOp=" / ";
            if(bN2.signum()!=0)bResDiv=bN1.divideAndRemainder(bN2);//Math.signum() tells you what sign a number is....
            //returns zero if the argument is zero, 1.0 if the argument is greater than zero,
            //-1.0 if the argument is less than zero
            bRes=bResDiv[0]; bRemainder=bResDiv[1];
if(sOp.equals(" / ") && bN2.signum()==0){
// showStatus("Cannot divide by zero");
} else {
outArea.append(bN1.toString() + sOp+bN2.toString() + " = " + bRes.toString() + "\n");
if(actionEvent.getSource()==btnDiv)outArea.append("Remainder = "+bRemainder.toString()+"\n");
public static void main(String[] args) {//the main method of the program.
new Calculator2().setVisible(true);
}

// This is a simple calculator that calculate 4 mathematical operations, addition,
// subtraction, multiplication and division.
// Author: Jean Chedid.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.Math.*;
import java.math.BigInteger;
public class Calculator2 extends JFrame implements ActionListener{
    JLabel lN1, lN2,lN3;//here are the Label.
    JTextField tN1, tN2;// here the place for the text field.
    JButton btnAdd,btnSub,btnMul,btnDiv,btnClear,btnSave; JTextArea outArea;//all our Button which are in the program.
    Calculator2(){//constructor.
        Box box=Box.createVerticalBox();//creation of the box.
        // input
        lN1=new JLabel("Write first number"); box.add(lN1);//creation of the input,the number which we want use.
        tN1=new JTextField(100); tN1.setEditable(true); box.add(tN1);//allows or prevents the user editing the text
        lN2=new JLabel("write second number"); box.add(lN2);
        tN2=new JTextField(100); tN2.setEditable(true); box.add(tN2);
        // buttons
        btnAdd=new JButton("+"); btnAdd.addActionListener(this); box.add(btnAdd);// button of addition operation
        // setPreferredSize();
        btnSub=new JButton("-"); btnSub.addActionListener(this); box.add(btnSub);// button of subtraction operation
        btnMul=new JButton("*"); btnMul.addActionListener(this); box.add(btnMul);// button of multiplication operation
        btnDiv=new JButton("/"); btnDiv.addActionListener(this); box.add(btnDiv);// button of division operation
        btnClear=new JButton("Clear"); btnClear.addActionListener(this); box.add(btnClear);// button of Clear operation
        btnSave=new JButton("Save"); btnSave.addActionListener(this); box.add(btnSave);// button of save operation
        // Output
        String desc="This is a simple integer calculator\n";//here the out put with text area.
        outArea=new JTextArea(desc,30,60);//out put area with the hight and length.
        ScrollPane scrollPane=new ScrollPane();//Creates an empty (no viewport view) JScrollPane where both horizontal and vertical scrollbars appear when needed
        scrollPane.add(outArea);
        box.add(scrollPane);
        Container c=getContentPane();
        c.add(box);
        c.setBackground(Color.green);//back ground color.
        setTitle("Calculator");//title
        setSize(600,375);//size
        setVisible(true);// visiblity of the program.
     private void showStatus(String status) {
     lN3.setText(status);
    public void actionPerformed(ActionEvent actionEvent){
        if(actionEvent.getSource()==btnClear){
            outArea.selectAll(); outArea.cut();
        } else {
            String sN1=tN1.getText(), sN2=tN2.getText(), sOp="";
            BigInteger bN1=new BigInteger(sN1);
            BigInteger bN2=new BigInteger(sN2);
            BigInteger bRes=BigInteger.ZERO, bResDiv[]={BigInteger.ZERO,BigInteger.ZERO};
            BigInteger bRemainder=BigInteger.ZERO;
            if(actionEvent.getSource()==btnAdd){bRes=bN1.add(bN2); sOp=" + ";}
            if(actionEvent.getSource()==btnSub){bRes=bN1.subtract(bN2); sOp=" - ";}
            if(actionEvent.getSource()==btnMul){bRes=bN1.multiply(bN2); sOp=" * ";}
            if(actionEvent.getSource()==btnDiv){sOp=" / ";
            if(bN2.signum()!=0)bResDiv=bN1.divideAndRemainder(bN2);//Math.signum() tells you what sign a number is....
            //returns zero if the argument is zero, 1.0 if the argument is greater than zero,
            //-1.0 if the argument is less than zero
            bRes=bResDiv[0]; bRemainder=bResDiv[1];
            if(sOp.equals(" / ") && bN2.signum()==0){
                // showStatus("Cannot divide by zero");
            } else {
                outArea.append(bN1.toString() + sOp+bN2.toString() + " = " + bRes.toString() + "\n");
                if(actionEvent.getSource()==btnDiv)outArea.append("Remainder = "+bRemainder.toString()+"\n");
    public static void main(String[] args) {//the main method of the program.
        new Calculator2().setVisible(true);
}

Similar Messages

  • How to store something in text file?

    Hello
    I have question and i do not know how to do this.
    can any one explain for me how i can save something in a text file.
    i create calculator,and there is one question i need to do it:((Store the record of the session in a text file. ))
    what i need to write some codes and so on.
    please can u give idea ?

    Alena,
    Here's my static FileUtilz class, which includes a writeFile method, and several other handy methods.
    package krc.io;
    import java.util.Collection;
    import java.util.List;
    import java.util.ArrayList;
    import java.io.File;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    import java.io.InputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.FileNotFoundException;
    import java.util.Arrays;
    public abstract class FileUtilz
        public static final int bfrSize = 4096;
        public static void writeFile(String content, String filename)
        throws IOException
            PrintWriter out = null;
            try {
                out = new PrintWriter(new FileWriter(filename));
                out.write(content);
            } finally {
                //try {if(out!=null)out.close();}catch(Exception ignore){}
                out.close();
        public static String readFile(String filename)
        throws IOException, FileNotFoundException
            FileReader in = null;
            StringBuffer out = new StringBuffer();
            try {
                in = new FileReader(filename);
                char[] cbuf = new char[bfrSize];
                int n = in.read(cbuf, 0, bfrSize);
                while(n > 0) {
                    out.append(cbuf);
                    n = in.read(cbuf, 0, bfrSize);
            } finally {
                //try {if(in!=null)in.close();}catch(Exception ignore){}
                in.close();
            return out.toString();
        public  static String[] readFileIntoArray(String filename)
        throws IOException, FileNotFoundException
            return readFileIntoList(filename).toArray(new String[0]);
        public  static List<String> readFileIntoList(String filename)
        throws IOException, FileNotFoundException
            BufferedReader in = null;
            List<String> out = new ArrayList<String>();
            try {
                in = new BufferedReader(new FileReader(filename));
                String line = null;
                while ( (line = in.readLine()) != null ) {
                    out.add(line);
            } finally {
                try {if(in!=null)in.close();}catch(Exception e){}
            return out;
        public static byte[] readBytes(String filename)
        throws IOException, FileNotFoundException
          //start = System.currentTimeMillis();
          File file = new File(filename);
          byte[] out = new byte[(int)file.length()];
          InputStream in = new FileInputStream(file);
          int size = in.read(out);
          in.close();
          //System.out.println("readBytes("+filename+"="+size") took "+(System.currentTimeMillis()-start));
          return out;
        public static boolean isSameFile(String filenameA, String filenameB)
        throws IOException, FileNotFoundException
          File fileA = new File(filenameA);
          File fileB = new File(filenameB);
          //check for same physical file
          if( fileA.equals(fileB) ) return(true);
          //compare sizes
          if( fileA.length() != fileB.length() ) return(false);
          //compare contents (buffer by buffer)
          boolean same=true;
          InputStream inA = null;
          InputStream inB = null;
          try {
            inA = new FileInputStream(fileA);
            inB = new FileInputStream(fileB);
            byte[] bfrA = new byte[bfrSize];
            byte[] bfrB = new byte[bfrSize];
            int sizeA=0, sizeB=0;
            do {
              sizeA = inA.read(bfrA);
              sizeB = inA.read(bfrB);
              if ( sizeA != sizeB ) {
                same=false;
              } else if ( sizeA == 0 ) {
                //do nothing
              } else if ( !Arrays.equals(bfrA,bfrB) ) {
                same=false;
            } while (same && sizeA != -1);
          } finally {
            if(inA!=null)inA.close();
            if(inB!=null)inB.close();
          return(same);
        public static String basename(String path, boolean cutExtension)
            String fname = (new File(path)).getName();
            if (cutExtension) {
                int i = fname.lastIndexOf(".");
                if (i > 0) {
                    fname = fname.substring(0,i);
            return fname;
        public static String dirname(String path)
            return (new File(path)).getParent();
    }

  • How to get the content of text file to write in JTextArea?

    Hello,
    I have text area and File chooser..
    i wanna the content of choosed file to be written into text area..
    I have this code:
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.*;
    public class Test_Stemmer extends JFrame {
    public Test_Stemmer() {
    super("Arabic Stemmer..");
    setSize(350, 470);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setResizable(false);
    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    JButton openButton = new JButton("Open");
    JButton saveButton = new JButton("Save");
    JButton dirButton = new JButton("Pick Dir");
    JTextArea ta=new JTextArea("File will be written here", 10, 25);
    JTextArea ta2=new JTextArea("Stemmed File will be written here", 10, 25);
    final JLabel statusbar =
                  new JLabel("Output of your selection will go here");
    // Create a file chooser that opens up as an Open dialog
    openButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ae) {
         JFileChooser chooser = new JFileChooser();
         chooser.setMultiSelectionEnabled(true);
         int option = chooser.showOpenDialog(Test_Stemmer.this);
         if (option == JFileChooser.APPROVE_OPTION) {
           File[] sf = chooser.getSelectedFiles();
           String filelist = "nothing";
           if (sf.length > 0) filelist = sf[0].getName();
           for (int i = 1; i < sf.length; i++) {
             filelist += ", " + sf.getName();
    statusbar.setText("You chose " + filelist);
    else {
    statusbar.setText("You canceled.");
    // Create a file chooser that opens up as a Save dialog
    saveButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    JFileChooser chooser = new JFileChooser();
    int option = chooser.showSaveDialog(Test_Stemmer.this);
    if (option == JFileChooser.APPROVE_OPTION) {
    statusbar.setText("You saved " + ((chooser.getSelectedFile()!=null)?
    chooser.getSelectedFile().getName():"nothing"));
    else {
    statusbar.setText("You canceled.");
    // Create a file chooser that allows you to pick a directory
    // rather than a file
    dirButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int option = chooser.showOpenDialog(Test_Stemmer.this);
    if (option == JFileChooser.APPROVE_OPTION) {
    statusbar.setText("You opened " + ((chooser.getSelectedFile()!=null)?
    chooser.getSelectedFile().getName():"nothing"));
    else {
    statusbar.setText("You canceled.");
    c.add(openButton);
    c.add(saveButton);
    c.add(dirButton);
    c.add(statusbar);
    c.add(ta);
    c.add(ta2);
    public static void main(String args[]) {
    Test_Stemmer sfc = new Test_Stemmer();
    sfc.setVisible(true);
    }could you please help me, and tell me what to add or to modify,,
    Thank you..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    realahmed8 wrote:
    thanks masijade,
    i have filter the file chooser for only text files,
    but i still don't know how to use FileReader to put text file content to the text area (ta) ..
    please tell me how and where to use it..How? -- See the IO Tutorials on Sun for the FileReader (and I assume you know how to call setText and append in the JTextArea).
    Where? -- In the actionPerformed method (better would be a separate thread that is triggered through the actionPerformed method, but that is probably beyond you at the moment), of course.
    Give it a try.

  • Where are these unix executable files coming from and how do I recover the original text file?

    where are these unix executable files coming from and how do I recover the original text file?

    When you upgraded to Lion did you have AppleWorks installed on your mac?
    Most of the AW documents can be opened by Pages 09 or Numbers 09 with most of the orginal format in tact. (I do not know if previouse verision will work) just open the AW file with both and see which one works best.
    Text Edit will also open most of the AW files as well but will require a lot of work to restore them to their orginal format.
    If you have AW Database documents then they are not supported. 
    These document show up as "exec icons", Kind: Unix Executagle File.
    They also will show up as .cwk file if they are small files. I have a couple that were under 1mb that are shown as " Kind: AppleWorks Document" but will not open.
    The only option to open AW database is to have AW installed on a mac with a pre-Lion OS to recover the file.

  • How can u insert and retrieve text files in any format using forms6i.

    how can u insert and retrieve text files in any format using forms6i.
    can u give me an example of an insert statement, let's assume the file is located in the a:drive.
    and retrieving the files, i would give the user a list of all the files that are in the database, the user would select one, but what command(or piece of code) would open the file in its apppropriate editor.
    e.g .pdf formatted file would open in acrobat.
    any help would be appreciated.
    Thanks
    Hussein Saiger

    the filereference class is for downloading and uploading files.
    if you want to load xml, use the xml class.
    and, if you want to write to an xml file and don't want to use server-side code, wait.

  • I have a 2tb time capsule wondering how to store a lot of my files and photos on it to free up some space on my hard drive on my iMac

    i have a 2tb time capsule wondering how to store a lot of my files and photos on it to free up some space on my hard drive on my iMac

    For iMac please use USB or even better a FW800 or if you can afford it, a thunderbolt drive.. on your 2011 Mac.
    Time Capsule is not a suitable place to store your files.
    1. You will have no backup.
    2. TC cannot back itself up, nor can Time Machine backup network drives.
    3. Apple says specifically of iphoto not to store library on network drive.
    iphoto network no no.
    http://support.apple.com/kb/HT1198
    It's recommended that you store your iPhoto library on a locally mounted hard drive. Storing your iPhoto library on a network share can lead to poor performance, data corruption, or data loss.
    https://discussions.apple.com/thread/6692100
    4. Other libraries may not corrupt but will run very slowly. iTunes for example.
    Please purchase the fastest drive out of the external ports you have available.. usb2 although the slowest is still faster than TC over gigabit. It is also more reliable. TC are not a noted reliable storage drive. It is designed as a backup location for TM files.

  • Powershell script - how to read a registry hive and store the value in text file and then again read the text file to write the values back in registry

    Hi All,
    powershell script Method required to read a value from registry and then taking the backup of that values in some text file.
    For example the hive is
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path
    and under path i need to take back up  of values in some text file and then put some value in the registry after back is taken in text file.
    Also how to read the text file values so that we can again write to registry hive  back from the back up text file.
    Your help is much appreciated.
    Umeed4u

    I think you need to read this first:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/a0def745-4831-4de0-a040-63b63e7be7ae/posting-guidelines?forum=ITCG
    Don't retire TechNet! -
    (Don't give up yet - 12,830+ strong and growing)

  • How to store the contents of a file

    Hi,
    I'm using forms6i and database 10g.
    Through forms if a user selects a filename , and clicks a button or something,
    the contents of the file should be saved in the database.
    The file can be of any type, like .doc,.pdf,.xml,.html etc...
    and the contents filed will be of type varchar
    Please help me do this..
    Thanks

    Do you really want to save the "Content" of a file or the file itself? If you try to save the contents of a .doc or .pdf in a column with a VARCHAR2 datatype, you are going to corrupt the contents of the file since these file types have binary data in them as well as text. I think you would have greater success storing the actual file in a BLOB column.
    Here are a few Oracle Support documents that discuss how to store and retrieve files stored as BLOBs in the database.
    Doc ID: 168277.1 - How to Upload Binary Documents Back to Database BLOB Column from Forms
    Doc ID: 330146.1 - How to write BLOBs Stored Inside the Database Out to Files.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to import data from a text file through DTS to Sql Server

    Please don't mistake me as i'm a new comer to sql server,please help me.
    how to import the data present in a plain text file through DTS into sql server and store the data in a temporary table.
    How far the temporary table is stored in the database.
    Please reply me as soon as possible.
    Thank you viewers.

    >
    I can say that anybody with
    no experience could easily do an export/import in
    MSSQLServer 2000.
    Anybody with no experience should not mess up my Oracle Databases !

  • How to save input from a text file in to array

    I got this assignment, and almost have no clue, and my teacher doesn't even teaches us anything
    This is what i am suppose to do
    5. The program must store the following data about each student in this Talent Show:
    * The student's name (store as a String)
    * The student's average time score [only for the events they competed in] (store as a Double)
    Note: Some of the data comes directly from the text file, and some of the data must be calculated from the data that is read from the file.
    6. The program must search through all of the student's scores to find the student who has the minumum average time of all students.
    7. You must calculate how many events each student played. Zero values are not counted.
    8. You must then generate a report on the screen that prints out
    * the total number of students in the competition,
    * the winning student's ...
    o name
    o times
    o average time (rounded to one decimal places)
    Sample output
    btw this is the data file
    Bart Simpson
    7.5
    12.3
    7.8
    19.2
    9.9
    5.3
    8.5
    11.8
    2.2
    4.6
    Stewie Griffin
    9.5
    29.7
    7.8
    22.5
    9.9
    12.6
    8.5
    0
    8.2
    0
    Pinky
    2.5
    0
    1.8
    0
    3.9
    0
    6.5
    0
    5.2
    12.1
    Rocky N Bullwinkle
    10.0
    22.2
    9.5
    17.5
    9.9
    1.5
    8.7
    23.7
    9.2
    11.0
    Angelica Pickles
    5.5
    11.1
    6.8
    12.2
    7.9
    13.3
    8.1
    5.1
    7.2
    7.9
    Pink Panther
    8.5
    5.5
    8.8
    6.6
    8.9
    7.7
    9.9
    8.8
    2.2
    9.9
    Josie
    9.5
    0
    8.8
    12.2
    9.9
    0
    8.5
    0
    9.2
    5.3
    Rogue
    8.5
    1.1
    7.8
    2.2
    7.9
    3.3
    7.5
    4.4
    8.2
    5.5
    Usagi Tsukino
    8.5
    15.5
    8.8
    30.1
    9.9
    19.7
    9.5
    11.0
    8.2
    8.6
    Yosemite Sam
    0
    15.2
    0
    29.5
    3.9
    0
    0
    16.0
    0
    7.7
    My code so far
    import java.io.*;
    public class test
        public static void main (String [] args)
            FileInputStream File1;
            DataInputStream In;
            String fileInput = "";
            try
               File1 = new FileInputStream ("data.txt");
                In = new DataInputStream (File1);
                while (In.available () > 0)
                    fileInput = In.readLine ();
                    System.out.println (fileInput);
                In.close ();
            catch (FileNotFoundException e)
                System.out.println ("Error - this file does not exist");
            catch (IOException e)
                System.out.println ("error=" + e.toString ());
    }My question, how do i save the data in to an array, and how do i seperatly save names in to different array, and their scores in to different arrays
    bte he said you can use scanner class
    Thanks
    Edited by: supahsain08 on Mar 26, 2008 2:55 PM

    supahsain08 wrote:
    Well, you are not in my class and you don't even know my teacher
    who are you to judge meHe is jaded by our experiences here. 99% of posters who complain that the teacher doesn't teach have adequate (note that I didn't say good) teachers, but it's the student who is failing to take responsibility for his own education. It is after all your responsibility and complaining won't help you any.
    Good luck.

  • How do I read from a text file that is longer than 65536 lines and write the data to an Excel spreadshee​t and have the data write to a new column once the 65536 cells are filled in a column?

    I have data that is in basic generic text file format that needs to be converted into Excel spreadsheet format.  The data is much longer than 65536 lines, and in my code I haven't been able to figure out how to carry over the data into the next column.  Currently the conversion is done manually and generates an Excel file that has a total of 30-40 full columns of data.  Any suggestions would be greatly appreciated.
    Thanks,
    Darrick 
    Solved!
    Go to Solution.

    No need to use nested For loops. No need for any loop anyway. You just have to use a reshape array function. The picture below shows how to proceed.
    However, there may be an issue if your element number is not a multiple of the number of columns : zero value elements will be added at the end of the last column in the generated 2D array. Now the issue depends on the way you intend store the data in the Excel spreadsheet : you could convert the data as strings, replace the last zero values with empty strings, and write the whole 2D array to a file (with the .xls extension ) using the write to spreadsheet function. Only one (minimal) problem : define the number of decimal digits to be used;
    or you could write the numeric array directly to a true Excel spreadsheet, using either the NI report generation tools or ActiveX commands, then replace the last elements with empty strings.
    We need more input from you to decide how to solve these last questions. 
    Message Edité par chilly charly le 01-13-2009 09:29 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Example_VI.png ‏10 KB

  • How to store the data of a file into an ArrayList?

    Hi! everyone.
    I want to know
    if I have a File, and the data in the file are type int, type String...
    And I have a ArrayList which is of type Question
    How do I store the data of that file into the ArrayList
    I tried to use the while loop(use the hasNextLine() to read the data line by line)
    But I cannot add data which are not of type Question to the ArrayList.
    Can you tell me what I should do, please?
    I also wonder that
    The data of the file are of many types, but when I try to read it with the nextLine(), the data all turn out to be of type String. Why?
    Thank you.
    Edited by: Terry001 on Apr 30, 2008 1:13 PM

    No, a line in the file is just part of a question
    The format of the file is like this:
    *<question type code>                    :     String*
    *<question point value>                    :     int*
    *<question category>                         :     String*
    *<question difficulty level>               :     int*
    *<question text>                              :     String*
    *<question correct answer>               :     String*
    *<optional question-specific data>     :     String*
    *<question terminator>                    :     String*
    And here is an example
    TF //TrueFalseQuestion
    5 //points value
    None //category
    3 //difficulty level
    The capital of the United States is Washington, D.C. //question text
    True // answer
    *** //quetion terminator
    I created an ArrayList in the Test class:
    private ArrayList<Question> questions; // Create inside constructor
        public Test (String name, String instr)
            testName = name;
            scoreEarned = 0;
            scorePossible = 0;
            instructions = instr;
            questions = new ArrayList<Question>(); //[MAX_NUMBER_OF_QUESTIONS];
        }And I tried to use the following method to store the data of the file to the ArrayList
    // This method loads a set of questions from a plain text file
        public void loadQuestionsFromFile(String fileName) throws FileNotFoundException
            try
                File fileReader = new File("input.txt");
                Scanner sc = new Scanner(fileReader);
                while (sc.hasNextLine())
                    // I don't know how to pass the data I got from the nextLine() method to the ArrayList because they are of different type
            catch (FileNotFoundException a)
                System.out.println(a);
        }    As all you said, I should create an Question object in the while loop
    Question temp = new Question ();But I have no idea how to pass the int and String to the Question object.
    Thank you

  • Store boolean array as text file

    Hi there
    I'm having some trouble storinge a 25x25 2D array of booleans in a text file.
    First I make the 2D array a 1D array, and then I change it to a number, but here something already goes wrong, not the full number is stored, presumably because the array is this big?
    Any help will be much appreciated!
    Solved!
    Go to Solution.
    Attachments:
    Store 2D boolean array LV10.vi ‏17 KB

    You can also convert the 2D boolean array into 1D array of numbers and save to text file and then read back to load the original 2D Boolean array
    The best solution is the one you find it by yourself
    Attachments:
    2D Boolean to String.vi ‏16 KB

  • How to do something with the moved file ???

    I bet it is easy, but as I am new to AppleScript, still need help..
    This is a folder action. When a new file is added to the folder, the folder action script runs, and if the file name contains a particular text, then the file is moved to another folder - in this case, it is moved to a folder on an external hard drive. It is described in this script:
    copy name of thisItem as string to FileName
    if FileName contains "House" then
    move thisItem to POSIX file "/Volumes/ALL/House/Season 5/"
    The problem is - in that folder (/Volumes/ALL/House/Season 5/) I also have set a folder action, that, for example, converts or opens every file added to folder. The things is that, it is rather slow to run 2 folder actions and I don't know why it is so, but I guess it is because of the external hard drive. My aim is to remove the folder action for the folder (/Volumes/ALL/House/Season 5/), and do everything in the initial folder action.
    So the question is - How can I operate with (for example, convert or open the newly added file) the file added in the folder (/Volumes/ALL/House/Season 5/) via the first folder action script?
    Or in other words, how do I use the newly added file? I tried to do it like this:
    copy name of thisItem as string to FileName
    if FileName contains "House" then
    move thisItem to POSIX file "/Volumes/ALL/House/Season 5/"
    open thisItem
    But obviously, it opens the original thisItem! So how can I do something with the newly added file in the location /Volumes/ALL/House/Season 5/ ???
    Cheers and sorry for my english!
    Message was edited by: reinisb

    But obviously, it opens the original thisItem! So how can I do something with the newly added file in the location /Volumes/ALL/House/Season 5/ ???
    That's easy - you know the file name and you know the directory you copied the file to, so instead of:
    open thisItem
    you just:
    open POSIX file "/Volumes/ALL/House/Season\ 5/" & FileName

  • Using ArrayList to store Lines in a text File

    Hey Guys,
    I have the following program that I am using to read a text file and store each word in each line in an ArrayList. But I am getting the following error;
    Exception in thread "main" java.util.ConcurrentModificationException
         at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:449)
         at java.util.AbstractList$Itr.next(AbstractList.java:420)
         at bus.OrderReader.parseLine(OrderReader.java:50)
         at bus.OrderReader.main(OrderReader.java:32) The code is as follows;
    package bus;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.util.Scanner;
    import java.util.Collection;
    import java.util.ArrayList;
    import java.util.Iterator;
    public class OrderReader {
        static Collection bread = new ArrayList();
        static Collection filling = new ArrayList();
        static Iterator iter1 = filling.iterator();
        static Iterator iter2 = bread.iterator();
         private static int counter;
    public static void main(String args[]){
        Scanner s = null;
        try {
            s = new Scanner(new BufferedReader(new FileReader("/Users/admin/Documents/workspace2/OBS/WebContent/WriteMe.txt")));
            s.useDelimiter("\r");
            while(s.hasNext()) {
                parseLine(s.next());
                counter++;
            s.close();
        catch(FileNotFoundException e) {
            System.out.println("cannot find the file");
            //ignore for now
        public static void parseLine(String line) {
            Scanner lineScanner = new Scanner(line);
            lineScanner.useDelimiter("#");
                bread.add(lineScanner.next());
                filling.add(lineScanner.next());
                System.out.println(iter1.next());
                System.out.println(iter2.next());
    }I do not understand why this does not work. Can someone please point me in the right direction?
    Thank You
    Jaz

    Instead of doing this:
    bread.add(lineScanner.next());
    filling.add(lineScanner.next());
    System.out.println(iter1.next());
    System.out.println(iter2.next());where presumably you're just printing what you just
    barely added, do this:
    Object breadObject = lineScanner.next();
    Object fillingObject = lineScanner.next();
    bread.add(breadObject);
    filling.add(fillingObject);
    System.out.println(breadObject);
    System.out.println(fillingObject);
    And get rid of the now unused iterators.Im not sure I understand quiet what is happening here. Are you creating a primitive data type of type Object and then storing all the values in that variable?
    why would I do this when this only allows me to view the very last element that was added to the list? I want to view the entire list.
    Thanks
    Jaz
    Message was edited by:
    DontKnowJack

Maybe you are looking for

  • Find all open windows and close them

    Hi, I'm writing an application that creates a new thread. This thread loads an other application from the filesystem and invokes the main method. When the thread loads an application that opens a frame, my application can stop the thread, but the fra

  • TEXT_IO.PUT_LINE resulting in partial file at a consistant size of 40KB

    Overview: In client server mode the report opens a file on the desktop, writes a tab delimited text line for a specific repeating frame and then closes the file. However, the resulting file is incomplete but the previewer displays the compete report

  • Problem with AVCHD

    I am having MAJOR problems in AE CS4 getting my 1920 x1080 .mts files (AVCHD from Sony HVC-F11) to export without serious unusable  flickering/stuttering although the exact same file exports fine in Premiere CS4 when burning in Encore CS4.  I'm not s

  • Macbook Pro (Late 2011) 15" - Hard Drive Replacement Problem

    Hi there guys, My standard 750GB Hitachi Hard Drive failed on me last week and after speaking to AppleCare who told me that my laptop was out of warranty, I decided to try and fix the problem myself as I have a few friends that have had the same issu

  • IMac 27" AMD Radeon HD 6970M 2048 MB - Video Problems

    I just got a brand new iMac 27" and am having issues with my video.  The last iMac I bought had video issues, and a couple months after owning it, Apple/AMD fixed the driver issue and it worked fine.   However, this video issue happens within 5 minut