Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6563609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:52:15+00:00 2026-05-25T13:52:15+00:00

Basically, what I do is copy text from a Word document (97-2003 Word Doc)

  • 0

Basically, what I do is copy text from a Word document (97-2003 Word Doc) to a text file or rich text file, and the Java scanning utility doesn’t like it for some reason.

Here is the class i have set up to deal with my file reading operations:

import java.io.*;
import java.lang.*;
import java.util.*;

public class FileReader 
{
    private Scanner read;

    public void openFile(String name, String path)
    {
        try
        {
            read = new Scanner(new File(path + "/" + name));
            System.out.println("Succesfully opened " + name + " in " + path + "!");
        }
        catch(Exception e)
        {
            System.out.println("Could not open file.");
        }
    }

    public boolean hasNextEntry()
    {
        boolean result = false;

        if(read.hasNext())
        {
            result = true;
        }
        return result;
    }

    public String getNextLine()
    {
        String result = "";
        try
        {
            result = read.nextLine();
        }
        catch(Exception e)
        {
            System.out.println("Error getting next line --> " + e);
        }
        return result;
    }
}

What i do in my Main function is:

FileReader fr = new FileReader();
String dir = System.getProperty("user.dir");
fr.openFile("Text.txt", dir);
String line = fr.getNextLine();

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:52:16+00:00Added an answer on May 25, 2026 at 1:52 pm

    Word .doc files are (proprietary format) binary files – there’s no “lines” to speak of. You can’t read them like you’re trying (as text).

    You’re calling Scanner.nextLine() which attempts to find the next line separator and return the text prior to it. I suspect it’s unable to find a line separator (or it just pukes trying to deal with a binary file).

    If your next question is, “How do I read them then?” … the answer is the Apache POI project

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically all I want is to load a Gziped file into a rich text
I'm basically trying to create a linked list from a text file and add
I have a program where I basically need to load Rich Text from a
Basically, I'm trying to selectively copy a table from one database to another. I
From what I understand the <include> tag is basically a copy and paste so
i have a website which is basically a omegle copy ( text version only
I have a class which is basically a copy of another class. public class
Basically I want to copy the behavior in iPhone's Calendar where the day of
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.