feiyu02
2024-08-13 b8cc591541b88dd2bb93f111f8e8075842dce7ca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cn.flightfeather.supervision.docx4j.simpleDemo;
 
import java.io.FileInputStream;
import java.util.Scanner;
 
/**
 * Where Word reports an error in a very large file,
 * XML-aware tools such as Visual Studio might have trouble
 * opening it.  This simple class will print out specified
 * lines of document.xml.
 * 
 * Note: this is really only useful if the file was
 * pretty printed at the time Word reported the error
 * (since otherwise the error will typically be somewhere
 *  on a very long line 1). 
 * 
 * @author jharrop
 *
 */
public class ErrorLineExtractor {
 
    public static void main(String[] args) throws Exception {
 
       String path = System.getProperty("user.dir") + "/document.xml";
 
       long count = 0;
       
        FileInputStream inputStream = null;
        Scanner sc = null;
        try {
            inputStream = new FileInputStream(path);
            sc = new Scanner(inputStream, "UTF-8");
            while (sc.hasNextLine()) {
                String line = sc.nextLine();
                // System.out.println(line);
                count++;
                
                if (count>1714250) {
                    System.out.println(count + ": " + line);
                }
                if (count>1714400) {
                    return;
                }
            }
            // note that Scanner suppresses exceptions
            if (sc.ioException() != null) {
                throw sc.ioException();
            }
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (sc != null) {
                sc.close();
            }
        }        
        
    }
}