Verify If a Word Document is Password Protected in Java

This article demonstrates how to verify if a Word document is password protected or not using Spire.Doc for Java.

The following image shows that the input Word document is protected with password:

Verify If a Word Document is Password Protected in Java

import com.spire.doc.Document;

public class DetectIfWordIsPasswordProtected {
    public static void main(String []args){
        //Detect if the Word document is password protected
        boolean isPasswordProtected = Document.isPassWordProtected("C:\\Users\\Administrator\\Desktop\\Sample.docx");
        if(isPasswordProtected)
        {
            System.out.println("The document is password protected.");
        }
        else
        {
            System.out.println("The document is not password protected.");
        }
    }
}

Output:

Verify If a Word Document is Password Protected in Java