What to import to use IOUtils.toString()?












17















I am trying to use IOUtils.toString() to read from a file.
However, I am getting an error saying "IOUtils cannot be resolved."



What am I supposed to be importing to allow me to use this function?



String everything = IOUtils.toString(inputStream);


Thanks










share|improve this question

























  • Use this.. stackoverflow.com/questions/14768166/ioutils-exception-android

    – Ahmed Z.
    May 14 '13 at 4:19
















17















I am trying to use IOUtils.toString() to read from a file.
However, I am getting an error saying "IOUtils cannot be resolved."



What am I supposed to be importing to allow me to use this function?



String everything = IOUtils.toString(inputStream);


Thanks










share|improve this question

























  • Use this.. stackoverflow.com/questions/14768166/ioutils-exception-android

    – Ahmed Z.
    May 14 '13 at 4:19














17












17








17


1






I am trying to use IOUtils.toString() to read from a file.
However, I am getting an error saying "IOUtils cannot be resolved."



What am I supposed to be importing to allow me to use this function?



String everything = IOUtils.toString(inputStream);


Thanks










share|improve this question
















I am trying to use IOUtils.toString() to read from a file.
However, I am getting an error saying "IOUtils cannot be resolved."



What am I supposed to be importing to allow me to use this function?



String everything = IOUtils.toString(inputStream);


Thanks







java apache io tostring






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 16 '16 at 15:24









Philip Kirkbride

8,2282686150




8,2282686150










asked May 14 '13 at 4:17









user2380101user2380101

86114




86114













  • Use this.. stackoverflow.com/questions/14768166/ioutils-exception-android

    – Ahmed Z.
    May 14 '13 at 4:19



















  • Use this.. stackoverflow.com/questions/14768166/ioutils-exception-android

    – Ahmed Z.
    May 14 '13 at 4:19

















Use this.. stackoverflow.com/questions/14768166/ioutils-exception-android

– Ahmed Z.
May 14 '13 at 4:19





Use this.. stackoverflow.com/questions/14768166/ioutils-exception-android

– Ahmed Z.
May 14 '13 at 4:19












4 Answers
4






active

oldest

votes


















25














import org.apache.commons.io.IOUtils;



If you still can't import add to pom.xml:



<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>


or for direct jar/gradle etc visit:
http://mvnrepository.com/artifact/commons-io/commons-io/2.5



Also since version 2.5 of commons-io method IOUtils.toString(inputStream) has been deprecated. You should use method with Encoding i.e.



IOUtils.toString(is, "UTF-8");





share|improve this answer





















  • 1





    it worked with me

    – user1
    Sep 25 '16 at 15:03











  • Is it deprecated in favor of what method?

    – Raffael Bechara Rameh
    Apr 4 '17 at 16:50











  • Same method name but with one additional parameter - encoding. 'IOUtils.toString(is, "UTF-8");'

    – Fryta
    Apr 9 '17 at 21:10











  • This is eating all my memory

    – Ravipati Praveen
    Jan 18 at 9:23











  • Of course! Why would it not be something like <groupId>org.apache.commons</groupId> or similar? Gaaaaaaaaaaaaaa thanks for answer.

    – granadaCoder
    Mar 8 at 14:26



















1














Alternatively you can try following way. It worked for me for reading public key for resource server



        final Resource resource = new ClassPathResource("public.key");
String publicKey = null;
try {
publicKey = new String(Files.readAllBytes(resource.getFile().toPath()), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}





share|improve this answer
























  • Not working for jar files.

    – Dilip Dalwadi
    Feb 7 at 14:49











  • Why did you add jar there ?

    – snj
    Feb 8 at 9:13











  • I am using nohup to run java project.

    – Dilip Dalwadi
    Feb 8 at 12:38











  • It should work for jar also even if you are running jar in background in linux machine. Please share the error.

    – snj
    Feb 8 at 16:18



















1














import org.apache.commons.io.IOUtils;






share|improve this answer





















  • 3





    Unable to import this. Please help

    – Vaibhav Jhaveri
    Apr 21 '15 at 11:50











  • Check the answer of @Fryta, you need to add a library to your project.

    – thuanle
    Feb 23 '17 at 3:58



















-2














Here is code for How to convert InputStream to String in Java using Apache IOUtils



Reference : https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/IOUtils.html



FileInputStream fis = new FileInputStream(FILE_LOCATION);
String StringFromInputStream = IOUtils.toString(fis, "UTF-8");
System.out.println(StringFromInputStream);


Let me know if you need more help.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16535032%2fwhat-to-import-to-use-ioutils-tostring%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    25














    import org.apache.commons.io.IOUtils;



    If you still can't import add to pom.xml:



    <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
    </dependency>


    or for direct jar/gradle etc visit:
    http://mvnrepository.com/artifact/commons-io/commons-io/2.5



    Also since version 2.5 of commons-io method IOUtils.toString(inputStream) has been deprecated. You should use method with Encoding i.e.



    IOUtils.toString(is, "UTF-8");





    share|improve this answer





















    • 1





      it worked with me

      – user1
      Sep 25 '16 at 15:03











    • Is it deprecated in favor of what method?

      – Raffael Bechara Rameh
      Apr 4 '17 at 16:50











    • Same method name but with one additional parameter - encoding. 'IOUtils.toString(is, "UTF-8");'

      – Fryta
      Apr 9 '17 at 21:10











    • This is eating all my memory

      – Ravipati Praveen
      Jan 18 at 9:23











    • Of course! Why would it not be something like <groupId>org.apache.commons</groupId> or similar? Gaaaaaaaaaaaaaa thanks for answer.

      – granadaCoder
      Mar 8 at 14:26
















    25














    import org.apache.commons.io.IOUtils;



    If you still can't import add to pom.xml:



    <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
    </dependency>


    or for direct jar/gradle etc visit:
    http://mvnrepository.com/artifact/commons-io/commons-io/2.5



    Also since version 2.5 of commons-io method IOUtils.toString(inputStream) has been deprecated. You should use method with Encoding i.e.



    IOUtils.toString(is, "UTF-8");





    share|improve this answer





















    • 1





      it worked with me

      – user1
      Sep 25 '16 at 15:03











    • Is it deprecated in favor of what method?

      – Raffael Bechara Rameh
      Apr 4 '17 at 16:50











    • Same method name but with one additional parameter - encoding. 'IOUtils.toString(is, "UTF-8");'

      – Fryta
      Apr 9 '17 at 21:10











    • This is eating all my memory

      – Ravipati Praveen
      Jan 18 at 9:23











    • Of course! Why would it not be something like <groupId>org.apache.commons</groupId> or similar? Gaaaaaaaaaaaaaa thanks for answer.

      – granadaCoder
      Mar 8 at 14:26














    25












    25








    25







    import org.apache.commons.io.IOUtils;



    If you still can't import add to pom.xml:



    <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
    </dependency>


    or for direct jar/gradle etc visit:
    http://mvnrepository.com/artifact/commons-io/commons-io/2.5



    Also since version 2.5 of commons-io method IOUtils.toString(inputStream) has been deprecated. You should use method with Encoding i.e.



    IOUtils.toString(is, "UTF-8");





    share|improve this answer















    import org.apache.commons.io.IOUtils;



    If you still can't import add to pom.xml:



    <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
    </dependency>


    or for direct jar/gradle etc visit:
    http://mvnrepository.com/artifact/commons-io/commons-io/2.5



    Also since version 2.5 of commons-io method IOUtils.toString(inputStream) has been deprecated. You should use method with Encoding i.e.



    IOUtils.toString(is, "UTF-8");






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 6 '16 at 22:43

























    answered Jun 6 '16 at 22:20









    FrytaFryta

    28536




    28536








    • 1





      it worked with me

      – user1
      Sep 25 '16 at 15:03











    • Is it deprecated in favor of what method?

      – Raffael Bechara Rameh
      Apr 4 '17 at 16:50











    • Same method name but with one additional parameter - encoding. 'IOUtils.toString(is, "UTF-8");'

      – Fryta
      Apr 9 '17 at 21:10











    • This is eating all my memory

      – Ravipati Praveen
      Jan 18 at 9:23











    • Of course! Why would it not be something like <groupId>org.apache.commons</groupId> or similar? Gaaaaaaaaaaaaaa thanks for answer.

      – granadaCoder
      Mar 8 at 14:26














    • 1





      it worked with me

      – user1
      Sep 25 '16 at 15:03











    • Is it deprecated in favor of what method?

      – Raffael Bechara Rameh
      Apr 4 '17 at 16:50











    • Same method name but with one additional parameter - encoding. 'IOUtils.toString(is, "UTF-8");'

      – Fryta
      Apr 9 '17 at 21:10











    • This is eating all my memory

      – Ravipati Praveen
      Jan 18 at 9:23











    • Of course! Why would it not be something like <groupId>org.apache.commons</groupId> or similar? Gaaaaaaaaaaaaaa thanks for answer.

      – granadaCoder
      Mar 8 at 14:26








    1




    1





    it worked with me

    – user1
    Sep 25 '16 at 15:03





    it worked with me

    – user1
    Sep 25 '16 at 15:03













    Is it deprecated in favor of what method?

    – Raffael Bechara Rameh
    Apr 4 '17 at 16:50





    Is it deprecated in favor of what method?

    – Raffael Bechara Rameh
    Apr 4 '17 at 16:50













    Same method name but with one additional parameter - encoding. 'IOUtils.toString(is, "UTF-8");'

    – Fryta
    Apr 9 '17 at 21:10





    Same method name but with one additional parameter - encoding. 'IOUtils.toString(is, "UTF-8");'

    – Fryta
    Apr 9 '17 at 21:10













    This is eating all my memory

    – Ravipati Praveen
    Jan 18 at 9:23





    This is eating all my memory

    – Ravipati Praveen
    Jan 18 at 9:23













    Of course! Why would it not be something like <groupId>org.apache.commons</groupId> or similar? Gaaaaaaaaaaaaaa thanks for answer.

    – granadaCoder
    Mar 8 at 14:26





    Of course! Why would it not be something like <groupId>org.apache.commons</groupId> or similar? Gaaaaaaaaaaaaaa thanks for answer.

    – granadaCoder
    Mar 8 at 14:26













    1














    Alternatively you can try following way. It worked for me for reading public key for resource server



            final Resource resource = new ClassPathResource("public.key");
    String publicKey = null;
    try {
    publicKey = new String(Files.readAllBytes(resource.getFile().toPath()), StandardCharsets.UTF_8);
    } catch (IOException e) {
    e.printStackTrace();
    }





    share|improve this answer
























    • Not working for jar files.

      – Dilip Dalwadi
      Feb 7 at 14:49











    • Why did you add jar there ?

      – snj
      Feb 8 at 9:13











    • I am using nohup to run java project.

      – Dilip Dalwadi
      Feb 8 at 12:38











    • It should work for jar also even if you are running jar in background in linux machine. Please share the error.

      – snj
      Feb 8 at 16:18
















    1














    Alternatively you can try following way. It worked for me for reading public key for resource server



            final Resource resource = new ClassPathResource("public.key");
    String publicKey = null;
    try {
    publicKey = new String(Files.readAllBytes(resource.getFile().toPath()), StandardCharsets.UTF_8);
    } catch (IOException e) {
    e.printStackTrace();
    }





    share|improve this answer
























    • Not working for jar files.

      – Dilip Dalwadi
      Feb 7 at 14:49











    • Why did you add jar there ?

      – snj
      Feb 8 at 9:13











    • I am using nohup to run java project.

      – Dilip Dalwadi
      Feb 8 at 12:38











    • It should work for jar also even if you are running jar in background in linux machine. Please share the error.

      – snj
      Feb 8 at 16:18














    1












    1








    1







    Alternatively you can try following way. It worked for me for reading public key for resource server



            final Resource resource = new ClassPathResource("public.key");
    String publicKey = null;
    try {
    publicKey = new String(Files.readAllBytes(resource.getFile().toPath()), StandardCharsets.UTF_8);
    } catch (IOException e) {
    e.printStackTrace();
    }





    share|improve this answer













    Alternatively you can try following way. It worked for me for reading public key for resource server



            final Resource resource = new ClassPathResource("public.key");
    String publicKey = null;
    try {
    publicKey = new String(Files.readAllBytes(resource.getFile().toPath()), StandardCharsets.UTF_8);
    } catch (IOException e) {
    e.printStackTrace();
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 21 '18 at 13:43









    snjsnj

    909




    909













    • Not working for jar files.

      – Dilip Dalwadi
      Feb 7 at 14:49











    • Why did you add jar there ?

      – snj
      Feb 8 at 9:13











    • I am using nohup to run java project.

      – Dilip Dalwadi
      Feb 8 at 12:38











    • It should work for jar also even if you are running jar in background in linux machine. Please share the error.

      – snj
      Feb 8 at 16:18



















    • Not working for jar files.

      – Dilip Dalwadi
      Feb 7 at 14:49











    • Why did you add jar there ?

      – snj
      Feb 8 at 9:13











    • I am using nohup to run java project.

      – Dilip Dalwadi
      Feb 8 at 12:38











    • It should work for jar also even if you are running jar in background in linux machine. Please share the error.

      – snj
      Feb 8 at 16:18

















    Not working for jar files.

    – Dilip Dalwadi
    Feb 7 at 14:49





    Not working for jar files.

    – Dilip Dalwadi
    Feb 7 at 14:49













    Why did you add jar there ?

    – snj
    Feb 8 at 9:13





    Why did you add jar there ?

    – snj
    Feb 8 at 9:13













    I am using nohup to run java project.

    – Dilip Dalwadi
    Feb 8 at 12:38





    I am using nohup to run java project.

    – Dilip Dalwadi
    Feb 8 at 12:38













    It should work for jar also even if you are running jar in background in linux machine. Please share the error.

    – snj
    Feb 8 at 16:18





    It should work for jar also even if you are running jar in background in linux machine. Please share the error.

    – snj
    Feb 8 at 16:18











    1














    import org.apache.commons.io.IOUtils;






    share|improve this answer





















    • 3





      Unable to import this. Please help

      – Vaibhav Jhaveri
      Apr 21 '15 at 11:50











    • Check the answer of @Fryta, you need to add a library to your project.

      – thuanle
      Feb 23 '17 at 3:58
















    1














    import org.apache.commons.io.IOUtils;






    share|improve this answer





















    • 3





      Unable to import this. Please help

      – Vaibhav Jhaveri
      Apr 21 '15 at 11:50











    • Check the answer of @Fryta, you need to add a library to your project.

      – thuanle
      Feb 23 '17 at 3:58














    1












    1








    1







    import org.apache.commons.io.IOUtils;






    share|improve this answer















    import org.apache.commons.io.IOUtils;







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 23 '18 at 5:27









    SMR

    5,65222852




    5,65222852










    answered Sep 30 '13 at 18:20









    kracejickracejic

    385414




    385414








    • 3





      Unable to import this. Please help

      – Vaibhav Jhaveri
      Apr 21 '15 at 11:50











    • Check the answer of @Fryta, you need to add a library to your project.

      – thuanle
      Feb 23 '17 at 3:58














    • 3





      Unable to import this. Please help

      – Vaibhav Jhaveri
      Apr 21 '15 at 11:50











    • Check the answer of @Fryta, you need to add a library to your project.

      – thuanle
      Feb 23 '17 at 3:58








    3




    3





    Unable to import this. Please help

    – Vaibhav Jhaveri
    Apr 21 '15 at 11:50





    Unable to import this. Please help

    – Vaibhav Jhaveri
    Apr 21 '15 at 11:50













    Check the answer of @Fryta, you need to add a library to your project.

    – thuanle
    Feb 23 '17 at 3:58





    Check the answer of @Fryta, you need to add a library to your project.

    – thuanle
    Feb 23 '17 at 3:58











    -2














    Here is code for How to convert InputStream to String in Java using Apache IOUtils



    Reference : https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/IOUtils.html



    FileInputStream fis = new FileInputStream(FILE_LOCATION);
    String StringFromInputStream = IOUtils.toString(fis, "UTF-8");
    System.out.println(StringFromInputStream);


    Let me know if you need more help.






    share|improve this answer




























      -2














      Here is code for How to convert InputStream to String in Java using Apache IOUtils



      Reference : https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/IOUtils.html



      FileInputStream fis = new FileInputStream(FILE_LOCATION);
      String StringFromInputStream = IOUtils.toString(fis, "UTF-8");
      System.out.println(StringFromInputStream);


      Let me know if you need more help.






      share|improve this answer


























        -2












        -2








        -2







        Here is code for How to convert InputStream to String in Java using Apache IOUtils



        Reference : https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/IOUtils.html



        FileInputStream fis = new FileInputStream(FILE_LOCATION);
        String StringFromInputStream = IOUtils.toString(fis, "UTF-8");
        System.out.println(StringFromInputStream);


        Let me know if you need more help.






        share|improve this answer













        Here is code for How to convert InputStream to String in Java using Apache IOUtils



        Reference : https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/IOUtils.html



        FileInputStream fis = new FileInputStream(FILE_LOCATION);
        String StringFromInputStream = IOUtils.toString(fis, "UTF-8");
        System.out.println(StringFromInputStream);


        Let me know if you need more help.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 17 '15 at 7:00









        Himanshu AroraHimanshu Arora

        123211




        123211






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16535032%2fwhat-to-import-to-use-ioutils-tostring%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?