What to import to use IOUtils.toString()?












16














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
















16














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














16












16








16


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

7,8882683149




7,8882683149










asked May 14 '13 at 4:17









user2380101

81114




81114












  • 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


















22














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



















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



















0














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





























    -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









      22














      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
















      22














      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














      22












      22








      22






      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









      Fryta

      24726




      24726








      • 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














      • 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








      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













      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,58222751




      5,58222751










      answered Sep 30 '13 at 18:20









      kracejic

      375314




      375314








      • 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











      0














      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


























        0














        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
























          0












          0








          0






          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









          snj

          809




          809























              -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 Arora

                  118211




                  118211






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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

                      Basket-ball féminin

                      Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

                      I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...