read output of txt file has white spaces

后端 未结 3 1183
囚心锁ツ
囚心锁ツ 2021-01-21 11:40

i got the list of applications from cmd command using /output:D:\\list.txt product get name,version. However when i try to retrieve the list using java the output has white spac

相关标签:
3条回答
  • 2021-01-21 12:16

    Looks like you read a UTF-16 encoded file.

    Give a hint to your Reader - pass "UTF-16", instead of "ISO-8859-1".

    0 讨论(0)
  • 2021-01-21 12:17

    This can be due to the encoding problem. Try using UTF-16 character set

    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-16"));
    
    0 讨论(0)
  • 2021-01-21 12:17

    Have you tried the FileReader?

    FileReader fileReader;
    try {
        fileReader = new FileReader( "D:\\list.txt" );
        BufferedReader bufferedReader = new BufferedReader( fileReader ); 
        String line; 
        while( ( line = bufferedReader.readLine() ) != null )
        { 
            System.out.println( line ); 
        }
        fileReader.close();
    } catch ( IOException except ) {
        System.err.println( except.getStackTrace()[0] );
    }
    

    Im not shure where your problem is coming from, but you may take the FileReader for such instructions.

    0 讨论(0)
提交回复
热议问题