Text file reading issue

Hi,

I am using the following snippet

Document doc1 = new Document("FilePAth of the Text Document");
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
doc1.save(outStream, SaveFormat.DOCX);
byte[] docBytes = outStream.toByteArray();
ByteArrayInputStream inStream = new ByteArrayInputStream(docBytes);
Document doc = new Document(inStream);
for (Paragraph para : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH, true))
{
    try
    {
        if (!(para.getAncestor(NodeType.FOOTNOTE).getNodeType() == NodeType.FOOTNOTE))
        {
        }
    }
    catch (Exception e)
    {
        try
        {
            if (!(para.getAncestor(NodeType.COMMENT).getNodeType() == NodeType.COMMENT))
            {
            }
        }
        catch (Exception e2)

        {
            try
            {
                if (para.getAncestor(NodeType.BODY).getNodeType() == NodeType.BODY)
                {
                    para.getListFormat().removeNumbers();
                    String text = para.toString(SaveFormat.TEXT);
                    System.out.println(text);
                }

The test Document is attached.
I am not getting the proper output in my console.

NOTE: Please adjust the braces if any issue faced

Hi Rajesh,

Thanks for your inquiry. We have executed the shared code example at our end. The output is “1 US 1”.

There is no need to save the document into stream (Docx file format). You can iterate through paragraph after loading the txt into Aspose.Words DOM. Could you please share some detail about your requirements along with expected output? We will then provide you more information on this along with code.

Hi Tahir,

I have tested the code again but getting the same result. Could u please look into it?

Regards,
Rajesh

Hi Rajesh,

Thanks for your inquiry. We have tested the scenario using following code example and output is “1 US 1”. Check the attached image for detail. Please make sure that you are using the same code and input document.

Document doc1 = new Document(MyDir + "Test.txt");
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
doc1.save(outStream, SaveFormat.DOCX);
byte[] docBytes = outStream.toByteArray();
ByteArrayInputStream inStream = new ByteArrayInputStream(docBytes);
Document doc = new Document(inStream);
for (Paragraph para : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH, true))
{
    try
    {
        if (!(para.getAncestor(NodeType.FOOTNOTE).getNodeType() == NodeType.FOOTNOTE))
        {
        }
    }
    catch (Exception e)
    {
        try
        {
            if (!(para.getAncestor(NodeType.COMMENT).getNodeType() == NodeType.COMMENT))
            {
            }
        }
        catch (Exception e2)
        {
            try
            {
                if (para.getAncestor(NodeType.BODY).getNodeType() == NodeType.BODY)
                {
                    para.getListFormat().removeNumbers();
                    String text = para.toString(SaveFormat.TEXT);
                    System.out.println(text);
                }
            }
            catch (Exception e3)
            {
            }
        }
    }
}