简体   繁体   English

Windows和linux关于FileInputStream读取之间有什么区别?

[英]what's differences between windows and linux about FileInputStream read?

for example, a file size is 1024 bytes that size is the same in windows and linux. 例如,文件大小为1024字节,该大小在Windows和Linux中相同。 but as I read the file like below 但是当我阅读如下文件时

FileInputStream fileInputStream = new FileInputStream(file);

for example, in windows, bytes length is 1026 but in linux, bytes length is 1024 or on the contrary to this in windows, bytes length is 1024 but in linux, bytes length is 1022 always in windows bytes length is greater than in linux. 例如,在Windows中,字节长度为1026,但在Linux中,字节长度为1024,或者与此相反,在Windows中,字节长度为1024,但在Linux中,字节长度始终为1022(在Windows中)字节长度大于Linux中的字节长度。

what's differences? 有什么区别?

The problem you are detecting probably has more to do with the Windows vs Unix line endings . 您检测到的问题可能与Windows vs Unix 行尾有关

As you must be reading the file in text mode, in Windows the end of a line is determined by the two symbols \\r\\n (represented in hexadecimal as 0x0A and 0x0D respectively), while in Unix systems it uses only \\n . 由于您必须以文本模式读取文件,因此在Windows中,行尾由两个符号\\r\\n (分别以十六进制表示为0x0A0x0D )确定,而在Unix系统中,它仅使用\\n

I'll make a wild guess and say your file has two lines. 我会做出一个疯狂的猜测,说您的文件有两行。 In Windows it will be replacing \\n by \\r\\n in each line end, creating 2 bytes that don't really exist in the original file. 在Windows中,它将在每一行末尾用\\r\\n替换\\n ,创建2个字节,这些字节在原始文件中实际上并不存在。

And in Linux, when reading a file generated in Windows, its doing the opposite, eating 2 bytes. 在Linux中,当读取Windows中生成的文件时,其操作相反,占用2个字节。

My guess is you are reading a text file and that file has been converted to use windows new lines which are \\r\\n instead of the linux \\n 我的猜测是您正在读取文本文件,并且该文件已转换为使用Windows新行,它们是\\r\\n而不是linux \\n

If you write text or binary without converting, the files will contain exactly the same bytes and exactly the same number of bytes. 如果您编写文本或二进制文件而不进行转换,则文件将包含完全相同的字节和完全相同的字节数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows 和 Debian (Linux) 上托管的 MySQL 有什么区别? - What are the differences between MySQL hosted on Windows and Debian (Linux)? 缓冲FileInputStream怎么样? - What about buffering FileInputStream? Java FileInputStream 在 Windows 和 Linux 中表现出不同的行为 - Java FileInputStream exhibits different behaviour in Windows and Linux 与Java的java.io.FileInputStream.read()等效的C ++是什么? - What's the C++ equivalent to Java's java.io.FileInputStream.read()? 本地(Windows / IntelliJ)和远程(Linux)在Maven构建上的差异? - Differences in Maven builds between local (Windows / IntelliJ) and remote (Linux)? Windows和Linux之间Java套接字的差异 - 如何处理它们? - Differences on Java Sockets between Windows and Linux - How to handle them? 在Windows和Linux之间加载ttf字体时JLabel的差异 - Differences in JLabel when loading ttf font between Windows and Linux FileInputStream.read(...) 和 RandomAccessFile 的区别 - Difference between FileInputStream.read(...) and RandomAccessFile FileInputStream.read(byte[]) 有什么问题? - What is wrong with FileInputStream.read(byte[])? FileChannel和FileInputStream中read(ByteBuffer)和read(byte [])之间的区别 - difference between read(ByteBuffer) and read(byte[]) in FileChannel and FileInputStream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM