Trying to read binary file as text but scanner stops at first line

后端 未结 3 1600
野的像风
野的像风 2021-01-27 02:56

I\'m trying to read a binary file but my program just stops at first line.. I think it\'s because of the strange characters the file has..I just want to extract some directions

3条回答
  •  爱一瞬间的悲伤
    2021-01-27 03:43

    As was said, since it is a binary file you can't use a Scanner or other character based readers. You could use a regular FileInputStream to read the actual raw bytes of the file. Java's String class has a constructor that will take an array of bytes and turn them into a string. You can then search that string for the file name(s). This may work if you just use the default character set.

    String(byte[]): http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html FileInputStream for reading bytes: http://download.oracle.com/javase/tutorial/essential/io/bytestreams.html

提交回复
热议问题