Java NegativeArraySizeException in byte

后端 未结 2 1784
谎友^
谎友^ 2021-01-24 23:11

I want to send file with OutputStream,

so I use byte[] = new byte[size of file ]

but I don\'t know what the max size is that i can use.

Th

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-24 23:56

    Well, this is a quite dangerous way to read files. int in Java is 32-bit int, so it resides in range -2147483648 - 2147483647, while long is 64 bit.

    Generally you shouldn't read the whole file at once because your program may exhaust your RAM on big files. Use a BufferedReader on top of FileReader instead.

提交回复
热议问题