Help loading a binary tree from file

Hi all,
So I am working on making a 20 question game using a binary tree. I have set it up so each time the user plays, if the computer cannot guess what they are thinking of, they tell the computer and it saves it. I am saving the tree in a text file recursively, in a format that looks something like this:
Do you use it outside?
a shovel
[null]
[null]
is it round?
a ball
[null]
[null]
a TV
[null]
[null]
The problem is now, I am having a very hard time rebuilding the tree when the user restarts the game. As you can see, the "{" indicates the beginning of a path and the "}" is the end. Can someone suggest a nice way to load this back up into my data structure? Thanks!!

Cross-post here: [http://www.java-forums.org/java-2d/14237-help-loading-binary-tree-file.html]
Recommended looking into XML

Similar Messages

  • Building a binary tree from a string

    I'm having trouble building a binary tree with shape described in a string.
    00 - means both left and right subtrees are empty;
    01 - means that the left is empty, and the right is not;
    10 - right is empty, left is not
    11 - neither are empty
    public BinaryTree(String s, Iterator it) {
    This constructor is supposed to build the binary tree of the specified shape and fills it with values. THe values come from Iterator it, and are placed into the tree in preorder fashion.
    I have to complete this constructor but I don't really know what to do. I was thinking I could use indexOf somehow. Any help would be greatly appreciated.
    Thanks,
    Mike

    I'd build it like this (this is from the top of my head, so no typo-free-warranties etc.) -- public class Tree {
       private Object data;
       private Tree left= null;
       private Tree right= null;
       private Tree(StringReader sr, Iterator di) {
          char l= (char)sr.read(); // left and right subtree indicators
          char r= (char)sr.read();
          data= di.next(); // set data for this node
          if (l == '1') left= new Tree(sr, di); // build left subtree
          if (r == '1') right= new Tree(sr, di); // build right subtree
       public Tree(String s, Iterator di) {
          this(new StringReader(s), di);
    } Note that the private constructor (the one that does all the work) doesn't handle incorrect strings
    at all, i.e. it'll crash horribly when the string passes contains, say an odd number of characters
    is is simply passing incorrect construction information. Also note that the Iterator must be able
    to iterate over enough elements to be set.
    kind regards,
    Jos

  • How to read data in binary form from file?

    Hi,
    i try to write an implementation of LZW. I need to read data in binary form from a file. How can i do that? I cannot find something like "binary input stream" ...
    Thanks

    Hi,
    i try to write an implementation of LZW. I need to
    read data in binary form from a file. How can i do
    that? I cannot find something like "binary input
    stream" ...
    ThanksInputStream reads bytes. I don't understand your question.

  • Searching for a certain  binary tree from another tree........

    I have been struggling for a tree search problem for a good while. Now I decide to ask you experts for a better solution :-).
    Given a binary tree A. We know that every Node of A has two pointers. Leaves of A can be tested by if(node.right = =node). Namely, The right pointer of every leaf node points to itself. (The left pointer points to the node sits on the left side of the leaf in the same depth. and the leafmost node points to the root. I do no think this information is important, am i right?).
    Tree B has a similar structure.
    The node used for both A and B.
    Node{
    Node left;
    Node right;
    My question is how to test if tree B is a subtree of A and if it is, returns the node in A that corresponds to the root of B. otherwise, return null.
    So, the method should look like:
    public Node search(Node rootOfA, Node rootOfB){
    I know a simple recursive fuction can do the job. The question is all about the effciency....
    I am wonderring if this is some kind of well-researched problem and if there has been a classical solution.
    Anyone knows of that? Any friend can give a sound solution?
    Thank you all in advance.
    Jason
    Message was edited by:
    since81

    I'm not too sure if this would help but there goes.
    I think a recursive function will be the easiest to implement (but not the most efficient). In terms of recursive function if you really want to add performance. You could implement your own stack and replace the recursive function with the use of this stack (since really the benefit of recursive function is that it manages its own stack). A non-recursive function with customized well implemented stack will be much more efficient but your code will become more ugly too (due to so many things to keep track of).
    Is tree B a separate instance of the binary tree? If yes then how can Tree B be a subset/subtree of tree A (since they are two separate "trees" or instances of the binary tree). If you wish to compare the data /object reference of Tree B's root node to that of Tree A's then the above method would be the most efficient according to my knowledge. You might have to use a Queue but I doubt it. Stack should be able to replace your recursive function to a better more efficient subroutine but you will have to manage using your own stack (as mentioned above). Your stack will behave similar to the recursive stack to keep track of the child/descendant/parent/root node and any other references that you may use otherwise.
    :)

  • Help with a binary tree

    I'm writing a binary tree class and am having some trouble with the Insert function. Here is the code for the TreeNode class...
    public class TreeNode
         TreeNode Left;
         TreeNode Right;
         String Name;
         public TreeNode(String NodeName)
              Left = null;
              Right = null;
              Name = NodeName;
    }And this is the code for the Tree class...
    public class Tree
         TreeNode Root;
         public Tree(String RootNode)
              Root = new TreeNode(RootNode);
         public void Insert(String Name)
              InsertNode(Root, Name);
         public void InsertNode(TreeNode t, String NodeName)
              if (t == null)
                   t = new TreeNode(NodeName);
              else
                   if (NodeName.compareTo(t.Name) < 0)
                        InsertNode(t.Left, NodeName);
                   else if (NodeName.compareTo(t.Name) > 0)
                        InsertNode(t.Right, NodeName);
                   else if (NodeName.compareTo(t.Name) == 0)
                        System.out.println("Entered node that was already in Tree");
    }When I enter a new node into a Tree containing just the root, it follows the recursion through once, then creates the new TreeNode as it should. However, the new node is not really recognized by the tree because when I try to insert another node, it only finds the root in the tree and only goes through one recursion. What's wrong?

    I believe t.Left (or t.Right) is getting set in the line
    t = new TreeNode(NodeName);
    Since it is a recursive function, when it is called the second time, the "t" that is passed in is actually the original t.left (I think), which is getting set then.

  • Traverse a binary tree from root to every branch

    I have a couple of other questions. I need to get all the different combinations of a binary tree and store them into a data structure. For the example in the code below, the combinations would be:
    1) Start, A1, A2, A3, B1, B2, B3
    2) Start, A1, A2, B1, A3, B2, B3
    3) Start, A1, A2, B1, B2, A3, B3
    4) Start, A1, A2, B1, B2, B3, A3
    5) Start, A1, B1, A2, A3, B2, B3
    etc.
    I understand that this is very similar to the preorder traversal, but preorder does not output the parent nodes another time when the node splits into a left and right node. Any suggestions?
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package binarytreetest;
    import java.util.ArrayList;
    import java.util.Iterator;
    * @author vluong
    public class BinaryTreeTest {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            int countA = 0;
            int countB = 0;
            ArrayList listA = new ArrayList();
            ArrayList listB = new ArrayList();
            listA.add("A1");
            listA.add("A2");
            listA.add("A3");
            listB.add("B1");
            listB.add("B2");
            listB.add("B3");
            //listB.add("B1");
            Node root = new Node("START");
            constructTree(root, countA, countB, listA, listB);
            //printInOrder(root);
            //printFromRoot(root);
        public static class Node{
            private Node left;
            private Node right;
            private String value;
            public Node(String value){
                this.value = value;
        public static void constructTree(Node node, int countA, int countB, ArrayList listA, ArrayList listB){
            if(countA < listA.size()){
                if(node.left == null){
                    System.out.println("There is no left node. CountA is " + countA);
                    System.out.println("Created new node with value: " + listA.get(countA).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.left = new Node(listA.get(countA).toString()); 
                    constructTree(node.left, countA+1, countB, listA, listB);   
                }else{
                    System.out.println("There is a left node. CountA + 1 is " + countA+1);
                    constructTree(node.left, countA+1, countB, listA, listB);   
            if(countB < listB.size()){
                if(node.right == null){
                    System.out.println("There is no right node. CountB is " + countB);
                    System.out.println("Created new node with value: " + listB.get(countB).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.right = new Node(listB.get(countB).toString());
                    constructTree(node.right, countA, countB+1, listA, listB);
                }else{
                    System.out.println("There is a right node. CountB + 1 is " + countB+1);
                    constructTree(node.right, countA, countB+1, listA, listB);
        }My second question is, if I need to add another list (listC) and find all the combinations of List A, listB and list C, is it correct to define the node class as
    public static class Node{
            private Node left;
            private Node mid;
            private Node right;
            private String value;
            public Node(String value){
                this.value = value;
        }Node left = listA, Node mid = listB, Node right = listC
    The code for the 3 lists is below.
    3 lists (A, B, C):
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package binarytreetest;
    import java.util.ArrayList;
    * @author vluong
    public class BinaryTreeTest {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            insert(root, "A1");
            insert(root, "A2");
            insert(root, "B1");
            insert(root, "B2"); 
            insert(root, "A2");
            int countA = 0;
            int countB = 0;
            int countC = 0;
            ArrayList listA = new ArrayList();
            ArrayList listB = new ArrayList();
            ArrayList listC = new ArrayList();
            listA.add("A1");
            listA.add("A2");
            //listA.add("A3");
            listB.add("B1");
            listB.add("B2");
            //listB.add("B3");
            //listB.add("B1");
            listC.add("C1");
            listC.add("C2");
            Node root = new Node("START");
            constructTree(root, countA, countB, countC, listA, listB, listC);
            //ConstructTree(root, countA, countB, listA, listB);
            //ConstructTree(root, countA, countB, listA, listB);
            printInOrder(root);
            //printFromRoot(root);
        public static class Node{
            private Node left;
            private Node mid;
            private Node right;
            private String value;
            public Node(String value){
                this.value = value;
        public static void constructTree(Node node, int countA, int countB, int countC, ArrayList listA, ArrayList listB, ArrayList listC){
            if(countA < listA.size()){
                if(node.left == null){
                    System.out.println("There is no left node. CountA is " + countA);
                    System.out.println("Created new node with value: " + listA.get(countA).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.left = new Node(listA.get(countA).toString()); 
                    constructTree(node.left, countA+1, countB, countC, listA, listB, listC);   
                }else{
                    System.out.println("There is a left node. CountA + 1 is " + countA+1);
                    constructTree(node.left, countA+1, countB, countC, listA, listB, listC);   
            if(countB < listB.size()){
                if(node.mid == null){
                    System.out.println("There is no mid node. CountB is " + countB);
                    System.out.println("Created new node with value: " + listB.get(countB).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.mid = new Node(listB.get(countB).toString());
                    constructTree(node.mid, countA, countB+1, countC, listA, listB, listC);
                }else{
                    System.out.println("There is a right node. CountB + 1 is " + countB+1);
                    constructTree(node.mid, countA, countB+1, countC, listA, listB, listC);
            if(countC < listC.size()){
                if(node.right == null){
                    System.out.println("There is no right node. CountC is " + countC);
                    System.out.println("Created new node with value: " + listC.get(countC).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.right = new Node(listC.get(countC).toString());
                    constructTree(node.right, countA, countB, countC+1, listA, listB, listC);
                }else{
                    System.out.println("There is a right node. CountC + 1 is " + countC+1);
                    constructTree(node.mid, countA, countB, countC+1, listA, listB, listC);
        }Thank you in advance!

    It looks to me like you are interleaving two lists. It looks like you are doing this while leaving the two subsequences in their original order.
    If that is in fact what you are doing, then this is just a combinatorics problem. Here is psuedo code (NOT java!)
    List path = new List();
    show(List A, int a, List B, int b, path){
      if(a >= A.length() && b >= b.length()){
        spew(path);
      } else {
        if(a < A.length()){path.push(A[a]); show(A,a+1,B,b,); path.pop();}
        if(b < B.length()){path.push(B); show(A,a,B,b+1,); path.pop();}
    show(A, 0, B, 0);
    In order to interleave 3 lists, you would add C and c arguments to the function and you would add one more line in the else block.

  • Help - error in reading frame from file

    Hi there
    Couldn't find any reference to this particular problem after searching around a whole load.
    I had my Mac crash on me a few days ago and since then I've been only able to work on my current project for ten minutes at a time before I get the above dialogue come up.
    It's not just this file that suffers from this and there doesn't appear to be a pattern to which file is affected. The files that are mentioned in the dialogue are outputs from both FCP and from AE itself, they are always Quicktimes and they are compressed with the Animation codec, although I've used a number of other codecs and it doesn't seem to make any difference. If I quit and restart AE, I can continue working for a while on a composition with the same file that caused the dialogue to appear, until it happens again, often with a different file mentioned in the dialogue.
    We have re-installed the CC suite after an uninstall and clean-up, but to no avail.
    Anyone else had this problem?
    Do we need to reinstall the OS? Could it be a quicktime thing?
    Many thanks for you help in advance.

    See this thread, on which one of my colleagues is helping folks troubleshoot some related issues:
    http://forums.adobe.com/message/5549272

  • Loading an external image (from file system) to fla library as MovieClip symbol.

    Hi everyone,
    I am new to actionscript and Flash.
    I have been working on code updation project wherein initially we had an image and text as movieclips in fla library. The image and the text are read by the actionscript program which then creates an animation.
    For Example:
    // Picture
    // _imageMC: Name of the Movie Clip in the libary which
    // contains the picture.
    var _imageMC:String = "polaroid";
    This is later on used by another actionscript class as follows to finally create the animation.
    var _mcPolaroid:MovieClip = this._mcBg.attachMovie(this._polaroid, "polaroid_mc", this._mcBg.getNextHighestDepth());
    Now the problem here is when one needs to update the image or text, one needs to go and open the fla file andmanually change the image attached to the movieClip (polaroid).
    I want to ease the updation process by giving the url of the image in an XML file. Read the image url from the xml and load this image in the library of the fla as movieclip. This, i think, will result in less code change and improve the updation of the final animation image.
    The problem i am facing is not been able to figure out how can i change the image (after fetching its URL) to a movieclip and then load it in the library?
    Thank you kindly in advance,
    Varun

    This is the AS3 forum and you are posting with regards to AS2 code.  Try posting in the AS2 forum...
    http://forums.adobe.com/community/flash/flash_actionscript
    As for the solution you seem to want.  You cannot dynamically add something to the library during runtime.  To add an image during runtime you would need to use the MovieClip.loadMovie() or MovieClipLoader.loadClip() methods.  You could have the movieclip pre-arranged in the library, but to add the image dynamically via xml information you need to load it into a movieclip, not the library.

  • Loading an external image (from file system) to fla library as MovieClip symbol using ActionScript.

    Hi everyone,
    I am new to actionscript and Flash.
    I have been working on code updation project wherein initially we had an image and text as movieclips in fla library. The image and the text are read by the actionscript program which then creates an animation.
    For Example:
    // Picture
    // _imageMC: Name of the Movie Clip in the libary which
    // contains the picture.
    var _imageMC:String = "polaroid";
    This is later on used by another actionscript class as follows to finally create the animation.
    var _mcPolaroid:MovieClip = this._mcBg.attachMovie(this._polaroid, "polaroid_mc", this._mcBg.getNextHighestDepth());
    Now the problem here is when one needs to update the image or text, one needs to go and open the fla file andmanually change the image attached to the movieClip (polaroid).
    I want to ease the updation process by giving the url of the image in an XML file. Read the image url from the xml and load this image in the library of the fla as movieclip. This, i think, will result in less code change and improve the updation of the final animation image.
    The problem i am facing is not been able to figure out how can i change the image (after fetching its URL) to a movieclip and then load it in the library?
    Thank you kindly in advance,
    Varun

    The following was my attempt: (i created a new MovieClip)
    this.createEmptyMovieClip("polaroidTest", this.getNextHighestDepth());
    loadMovie("imagefile.jpg", polaroidTest)
    var _imageMC:String = "polaroidTest";
    This mentioned variable _imageMC is read by a MovieClip class(self created as follows)
    /////////////////////////////// CODE STARTS //////////////////////////////////////
    class as.MovieClip.MovieClipPolaroid {
    private var _mcTarget:MovieClip;
    private var _polaroid:String;
    private var _mcBg:MovieClip;
    private var _rmcBg:MovieClip;
    private var _w:Number;
    private var _h:Number;
    private var _xPosition:Number;
    private var _yPosition:Number;
    private var _border:Number;
    * Constructor
        function MovieClipPolaroid(mcTarget:MovieClip, polaroid:String) {
    this._mcTarget = mcTarget;
    this._polaroid = polaroid;
    init();
    * initialise the polaroid movieclip and reflecting it
        private function init():Void {
    this._border = 10;
    this.initSize();
    this.setPosition(48,35);
    this.createBackground();
    var _mcPolaroid:MovieClip = this._mcBg.attachMovie(this._polaroid, "polaroid_mc", this._mcBg.getNextHighestDepth());
    _mcPolaroid._x = _border;
    _mcPolaroid._y = _border;
    var _rmcPolaroid:MovieClip=this._rmcBg.attachMovie(this._polaroid,"rpolaroid_mc", this._rmcBg.getNextHighestDepth());
    _rmcPolaroid._yscale *=-1;
    _rmcPolaroid._y = _rmcPolaroid._y + _h + _border ;
    _rmcPolaroid._x =_border;
    * create the background for the polaroid
    private function createBackground():Void {
    this._mcBg = _mcTarget.createEmptyMovieClip("target_mc",_mcTarget.getNextHighestDepth());
    this._rmcBg = _mcTarget.createEmptyMovieClip("rTarget_mc", _mcTarget.getNextHighestDepth());
    fill(_mcBg,_w+2*_border,_h+2*_border,100);
    fill(_rmcBg,_w+2*_border,_h+2*_border,10);
    placeBg(_mcBg,_w+2*_border,_yPosition);
    placeBg(_rmcBg,_w+2*_border,_h+2*_border+_yPosition);
    * position the background
    private function placeBg(mc:MovieClip,w:Number,h:Number) : Void {  
        mc._x = Stage.width - w - _xPosition;
    mc._y = h;
    * paint the backgound
    private function fill(mc:MovieClip,w:Number,h:Number, a:Number): Void {
    mc.beginFill(0xFFFFFF);
    mc.moveTo(0, 0);
    mc.lineTo(w, 0);
    mc.lineTo(w, h);
    mc.lineTo(0, h);
    mc.lineTo(0, 0);
    mc.endFill();
    mc._alpha=a;
    * init the size of the polaroid
    private function initSize():Void {
    var mc:MovieClip =_mcTarget.createEmptyMovieClip("mc",_mcTarget.getNextHighestDepth());
    mc.attachMovie(this._polaroid,"polaroid_mc", _mcTarget.getNextHighestDepth());
    this._h = mc._height;
    this._w = mc._width;
    removeMovieClip(mc);
    mc = null;
    * sets the position of the polaroid
    public function setPosition(xPos:Number,yPos:Number):Void {
    this._xPosition = xPos;
    this._yPosition = yPos;
    * moving in
    public function moveIn():Tween {
    var mc:MovieClip = this._mcTarget;
    mc._visible=true;
    var tween:Tween = new Tween(mc, "_x", Strong.easeOut, 0, 0, 1, true);
    var tween:Tween = new Tween(mc, "_y", Strong.easeOut, 200, 0, 1, true);
    var tween:Tween = new Tween(mc, "_xscale", Strong.easeOut, 30, 100, 1, true);
    var tween:Tween = new Tween(mc, "_yscale", Strong.easeOut, 30, 100, 1, true);
    var tween:Tween = new Tween(mc, "_alpha", Strong.easeOut, 0, 100, 1, true);
    return tween;
    * moving in
    public function moveOut():Tween {
    var mc:MovieClip = this._mcTarget;
    var tween:Tween = new Tween(mc, "_alpha", Strong.easeIn, 99, 0, 1, true);
    var tween:Tween = new Tween(mc, "_x", Strong.easeIn,0, 1000, 1, true);
    var tween:Tween = new Tween(mc, "_y", Strong.easeIn, 0, -50, 1, true);
    var tween:Tween = new Tween(mc, "_xscale", Strong.easeIn, 100, 50, 1, true);
    var tween:Tween = new Tween(mc, "_yscale", Strong.easeIn, 100, 50, 1, true);
    return tween;
    /////////////////////////////// CODE ENDS ///////////////////////////////////////
    As in the current case, the name of the movieclip which has the image (originally polaroid) is being read through the variable _imageMC which we hadd given the value "polaroidTest".
    The animation shows no image even when i have inserted the correct url (i m sure this step isn't wrong).
    Any clues?

  • Urgent help needed - writing/ reading to/from file

    hi all..
    can anyone help me with this problem:
    The problem dioscussed in www.javaworld.com forum
    any clues what the problem is??

    hi all...
    i managed to get the gui set up, and the JList is finally loading the data,
    yet, i am having problems with displaying relevant data of each item in the list...
    could you please help??
    // required imports
       import javax.swing.*;
       import java.awt.*;
       import java.awt.event.*;
       import javax.swing.event.*;
       import java.io.*;
       import java.util.*;
    // ViewPanel class: the panel for the view pane. handles its own events.
       public class ViewPanel extends JPanel implements ListSelectionListener
          private JList list;
          private DefaultListModel listModel;
          private JButton deleteButton;
          private TicketStorage data;
       // add pane items
          private JLabel seat, seatData;
          private JLabel name, nameData;
          private JLabel duration, durationData;
          private JLabel price, priceData;
          private JCheckBox waiterService;
       // creating panels
          JPanel p1 = new JPanel();
          JPanel p2 = new JPanel();
          public ViewPanel(TicketStorage data)
          // store data structure reference
             this.data = data;
             TrainTicket[] summary = data.summary();         
             listModel = new DefaultListModel();
             for (int i = 0; i < summary.length; i++)
                listModel.addElement(summary.getSeat());
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    list.setVisibleRowCount(5);
    JScrollPane listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(100, 150));
    seat = new JLabel("Seat No:");
    seatData = new JLabel();
    name = new JLabel("Name:");
    nameData = new JLabel();
    duration = new JLabel("Duration:");
    durationData = new JLabel();
    price = new JLabel("Price:");
    priceData = new JLabel();
    // create add pane items
    waiterService = new JCheckBox("Waiter Srevice");
    waiterService.setEnabled(false);
    // waiterService.addActionListener(boxListener);
    JButton deleteButton = new JButton("Delete");
    // deleteButton.addActionListener(buttonListener);
    // adding listeners to the components
    //deleteButton.addActionListener(this);
    //waiterService.addActionListener(this);
    list.addListSelectionListener(this);
    // adding the components to their coreesponding panels
    p1.setLayout(new GridLayout(5,1));
    p1.add(seat);
    p1.add(name);
    p1.add(duration);     
    p1.add(price);
    p1.add(waiterService);
    p2.setLayout(new GridLayout(5,1));
    p2.add(seatData);
    p2.add(nameData);
    p2.add(durationData);     
    p2.add(priceData);
    p2.add(deleteButton);
    this.setLayout(new GridLayout(1,3,3,0));
    this.add(listScroller);
    this.add(p1);     
    this.add(p2);
    public void valueChanged(ListSelectionEvent e)
    if (e.getValueIsAdjusting() == true)
    // enable the delete button when an item is selected
    deleteButton.setEnabled(true);
    // retrieve the sellected seat number value
    String itemSellected = listModel.getElementAt(list.getSelectedIndex()).toString();
    // retrieve the ticket with the sellected seat number
    TrainTicket tk = data.retrieve(itemSellected);
    // load the relevant data of a sellected ticket
    seatData.setText(tk.getSeat());
    nameData.setText(tk.getName());
    durationData.setText(Integer.toString(tk.getDuration()));
    priceData.setText(Double.toString(tk.getPrice()));
    /*/ if the selected ticket of type first class
    if(tk instanceof FirstClassTicket)
    if(((FirstClassTicket)tk).getWaiter()==true)
    waiterService.setSelected(true);
    waiterService.setEnabled(true);
    else
    waiterService.setSelected(false);
    waiterService.setEnabled(true);
    else
    waiterService.setSelected(false);
    waiterService.setEnabled(false);
    the application runs, it loads the data available in the linked list,
    yet, on switching from an item to another in the list, it keeps generating errors!!!
    in addition to the fact that it does not display the data!!
    for more info refer to the url in my first post!
    any clues??

  • Saving and loading 1D array to/from file

    Hi,
    i have some problems with my NI application. for the first, i have case structure with two cases: true and false.
    FALSE: in this case i have a for loop with 100 samples. i catch signal from my DAQ (now just Simulate Signal) and what i want is to save it in a 1D array and at the end of the loop the COMPLETE array into one text file. Problem in my vi: just the values from the last iteration are saved.
    TRUE: now i have while loop. AT THE BEGINN of the loop i need to load my array from the file and not in the middle of the loop. Why? The data from the file are needed during the loop.
    thanx in advance
    Vedran Divkovic
    RUB GERMANY
    Attachments:
    Regelsystem.vi ‏1494 KB

    According to your code, what you are saving is an array of means (one from each iteration), and NOT the last iteration. If you want to keep the entire data, it would be a 2D array.
    Why are you generating an entire waveform at each iteration? Shouldn't you just generate one point?
    LabVIEW Champion . Do more with less code and in less time .

  • Help with deleting multiple strings from file.......

    I am trying to delete the same string that may appear multiple times in the file. Here is the output to the screen. Here is the code. I have been researching the delete method it says that I have to start at an index position in the string but how would I find out where the multiples strings reside in the file? I am getting the feeling that it won't work for my purpose..???? I am trying to delete all ot the strings "a string of data3" from the file.
    Output
    C:\TestRead>java StringDelete
    Temp String file_data-------- a string of data3a string of data2a string of data
    1a string of data3a string of data2a string of data1a string of data3
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    String toDelete-------- a string of data3
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    String toDelete-------- a string of data2
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    String toDelete-------- a string of data1
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    String toDelete-------- a string of data3
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    String toDelete-------- a string of data2
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    String toDelete-------- a string of data1
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    String toDelete-------- a string of data3
    Just A Blank Line
    Just A Blank Line
    Just A Blank Line
    Code:
    import java.io.*;
    public class StringDelete
    public static void main(String [] args)
    try
    FileInputStream fis = new FileInputStream("TestFile.txt");
    DataInputStream in = new DataInputStream(fis);
    StringBuffer file_data = new StringBuffer();
    while(in.available() > 0)
    String temp = in.readUTF(); // read in a string from the file
    file_data.append(temp); // append it to the buffer
    System.out.println("Temp String file_data-------- " + file_data);
    System.out.println("Just A Blank Line");
    System.out.println("Just A Blank Line");
    System.out.println("Just A Blank Line");
    boolean keepGoing = true;
    while(keepGoing)
    String toDelete = file_data.substring(0, "a string of data3".length());
    System.out.println("String toDelete-------- " + toDelete);
    System.out.println("Just A Blank Line");
    System.out.println("Just A Blank Line");
    System.out.println("Just A Blank Line");
    if(toDelete == null || toDelete.equals("") )
    keepGoing = false;
    else
    file_data.delete(0,"a string of data3".length());
    catch(IOException e)
    e.printStackTrace();

    Here is the output. I am trying to get each part to work before I go on to the next part that is why some code is commented out.
    I need help to know why string "a string of data3" is not deleted in the towrite string??
    Output:
    C:\TestRead>java NewStringDelete
    String v after remove [ &#9668;a string of data3 &#9668;a string of data2 &#9668;a string of data1
    &#9668;a string of data3 &#9668;a string of data2 &#9668;a string of data1 &#9668;a string of data3]
    String towrite after remove &#9668;a string of data3 &#9668;a string of data2 &#9668;a string of
    data1 &#9668;a string of data3 &#9668;a string of data2 &#9668;a string of data1 &#9668;a string of data
    3
    Code:
    import java.util.Vector;
    import java.io.*;
    public class NewStringDelete
         public static void main(String [] args)
              //String ls = System.getProperty("line.separator");
              //File file;
              Vector v=new Vector();
         try{
              BufferedReader br=new BufferedReader(new FileReader ("TestFile.txt"));
              String s;
              while ((s=br.readLine())!=null)
                   {v.addElement(new String(""+s));}
                        br.close();
         catch(IOException e)
                   e.printStackTrace();
    /*now you have a Vector containing String objects..*/
         String remove = ("a string of data3");
         String towrite="";
    System.out.println("String v after remove " + v);     
         for (int i=0; i<v.size();i++)
              String ss = (String)v.elementAt(i);
              if (ss.equalsIgnoreCase(remove)){continue;}
              //     towrite=towrite+ss+ls;
                   towrite=towrite+ss;
    System.out.println("");               
    System.out.println("");               
    System.out.println("String towrite after remove " + towrite);                    
    /*do filewrite*/
    //try{
    // FileWriter fw=new FileWriter(TestFile.txt);
    // fw.write(towrite);
    // fw.close();
    // catch(IOException e)
    //               e.printStackTrace();

  • Urgent!! Help me - Read formatted data from file

    Hi,
    I have a file which contains(line by line) :
    [0.0577, 0.0769, 0.0385, 0.0, 0.0]
    [0.0577, 0.1346, 0.0962, 0.0, 0.0]
    [0.0192, 0.0, 0.0577, 0.1154, 0.0962]
    How can i read the file line by line(exluded "[" and "]" symbols) and assign each line to an array?
    Thanks

    full code regarding readin/writing
    import java.net.*;
    import java.io.*;
    import java.util.*;
         public class FtpWrite {
                   static StringBuffer Data = new StringBuffer(20);
             public static void main(String[] args) throws Exception {
                   int jobNumber = 10006;
                   String dataOut = "Liam Charles Rangers";
                   URL ftpUrl = new URL("ftp://username:[email protected]/dataOutput.txt");
                           URLConnection conn = ftpUrl.openConnection();
                   conn.setDoOutput(true);
                           OutputStream out = conn.getOutputStream();
                   PrintWriter writer = new PrintWriter(out);
                           System.out.println("Writing to ftp");
                   writer.print(jobNumber);
                   writer.print('\t');
                   writer.print(dataOut);
                   writer.print('\n');
                           writer.close();
                   out.close();
                   String dataIn;
                   InputStream inFile = ftpUrl.openStream();
                   BufferedReader in = new BufferedReader(new InputStreamReader(inFile));
                   dataIn = in.readLine();
                   System.out.println("The data is" + dataIn);
                   in.close();
                     StringTokenizer parser = new StringTokenizer(dataIn);
                       while (parser.hasMoreTokens()) {
                             System.out.println(parser.countTokens());
                             processWord(parser.nextToken(),parser.countTokens());}
                   public static void processWord(String token, int position){
                   int jobNumber = 0;
                   System.out.println("in process word token = " + token + " at position" + position );
                   if (position == 3)
                        jobNumber = Integer.parseInt(token);
                   jobNumber = jobNumber * 2;
                   System.out.println(jobNumber);
                   if((position <3) && (position>=0))
                        Data.append(token);
                        Data.append(' ');
                   System.out.println("Data is " + Data);
    }this code has just been completed with a bit of help. I gave it to you warts and all.
    Jim

  • Looking for code creating binary tree from expression(prefix)!

    I wanna use expression to generate binary expression tree. For example:
    I have expression in string: 1+2*3;
    then generate a tree like:
    +
    1 *
    2 3
    does some body have example code?

    sniff sniff I thought we were having lasagna? Smells like homework!

  • Using srw to load graphics from file in different path

    Hi all,
    I work with report 6i and I want to build a report with dynamic graphics. I stored the file name and directory in field of my data base.
    I want to know if it is possible to load graphics in report with package srw. If it is possible, can you tell me how can I proceed?
    best regard.

    Not sure if this option is available in reports 6i, but in reports help contents search for:
    'read from file'
    In data model get the database field having image path. In report layout, open property inspector of this field and change property 'Read from File' from No to Yes and also change property 'File Format'.

Maybe you are looking for

  • My spry horizontal menu bar is now displaying vertical. How do I fix it?

    My horizontal spry menu bar displays correctly at http://www.matthewvandyke.com/ar/photos/ but displays vertical at http://www.matthewvandyke.com/ar/about.html.  It started doing this a few days ago and I am not sure why. Can anyone take a look at th

  • 2 different size displays- different settings

    Hi. New to Mac. Just got a new i5 Mini a week ago. I have a older 19" LCD monitor that has a VGA-mac adaptor on it, and I have a HDMI cable going to my 60" plasma TV-via my HT receiver. I mirror the images and can see both screens ok, but to make the

  • Home page banner is slow loading

    I am creating a new corporate web site which has two .swf files on the home page and at the top is a small banner file (30k). For some reason, this banner takes 5 - 10 seconds to load and it happens well after both .swf files have loaded. Here's a UR

  • Create Document Info Record (DIR)

    Hi Experts, I have to Create document info records to store product specification information in DMS. Can any one tell me the process how to proceed for the same. Regards, Krishna Singh.

  • Webi snapshot not displaying selected drillfilters of report

    I am using business objects enterprise xi 3.1 fixpack 1.5 (12.1.5.1096)  on the Java Platform. I have created a web intelligence report with drillfilters that  used as a dropdown selection at the top of the report.  one contains a list of countries f