public static boolean serializeTree(TreeNode root)
    {
        Queue<TreeNode> nodeQueue = new LinkedList<TreeNode>();
        StringBuilder treeString = new StringBuilder();

        nodeQueue.add(root);

        while(!nodeQueue.isEmpty())
        {
            TreeNode curNode = nodeQueue.remove();

            if(curNode == null)
                treeString.append("# ");
            else
            {
                nodeQueue.add(curNode.getLeft());
                nodeQueue.add(curNode.getRight());
                treeString.append(curNode.getValue()+" ");
            }
        }
        try
        {
            PrintWriter file = new PrintWriter("D:\\Dev\\Java\\tree.txt");
            file.print(treeString);
            file.close();
            return true;
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
            return false;
        }
    }