How to convert FileInputStream into string in java? -


in java project, i'm passing fileinputstream function, need convert (typecast fileinputstream string), how it.??

public static void checkfor(fileinputstream fis) {    string a=new string;    a=fis         //how convert fileinputstream string    print string here } 

you can't directly convert string. should implement add code method

    //commented out because not efficient way achieve     //stringbuilder builder = new stringbuilder();     //int ch;     //while((ch = fis.read()) != -1){     //  builder.append((char)ch);     //}     //               //system.out.println(builder.tostring()); 

use aubin's solution:

public static string getfilecontent(    fileinputstream fis,    string          encoding ) throws ioexception  {    try( bufferedreader br =            new bufferedreader( new inputstreamreader(fis, encoding )))    {       stringbuilder sb = new stringbuilder();       string line;       while(( line = br.readline()) != null ) {          sb.append( line );          sb.append( '\n' );       }       return sb.tostring();    } } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -