String
s can hold a lot of data* - I'd be more concerned about your available heap memory if you're putting a whole file into memory that way. Especially as you have to be careful not to have it in memory twice for the base64 conversion...
*String
is internally backed by an array and can hold up tp Integer.MAX_VALUE characters (2^31-1)
If you do have enough heap memory for your process you can calculate like this:
- A char value in Java takes up 2 bytes of memory
- Every character of your base64 encoded file takes of two bytes internally
- base64 encoding makes 4 characters out of 3 bytes.
Apply some math and see if it fits or think hard and long why you need that data in memory in the first place.