base64 encoding .txt file

Concatenating one character at a time like this, into a String object, is almost certainly going to use up all your RAM. Try another method.

i do not know any other methods

Here's one:

/*----------------------------------------------------------------------------*/
/* addchr(buf,c) - add character to end of NUL-terminated string              */
/* Note: char array at buf must be large enough to add contain the added char */
/* Written by Morris Dovey (mrdovey@iedu.com)                                 */
/*----------------------------------------------------------------------------*/
char *addchar(char *buf,char c)
{  char *p = buf;                      /* Working output pointer              */
   while (*p) ++p;                     /* Find the terminating NUL character  */
   *p++ = c;                           /* Replace NUL with caller's char      */
   *p = '\0';                          /* Re-terminate the string             */
   return buf;                         /* Return pointer to start of string   */
}                                      /*  end: addchar()                     */
/*----------------------------------------------------------------------------*/