Skip to main content

Posts

Showing posts from November, 2013

How to Convert InputStream to String in Java

/** * read a file and converting it to String using StringBuilder */ public static String stringBuilder(String fileName) throws IOException { StringBuilder sbuilder = null; FileInputStream fStream = null; BufferedReader input = null; try { fStream = new FileInputStream(fileName); input = new BufferedReader(new InputStreamReader(fStream, "UTF-8")); sbuilder = new StringBuilder(); String str = input.readLine(); while (str != null) { sbuilder.append(str); str = input.readLine(); if (str != null) { sbuilder.append("\n"); } } } finally { input.close(); fStream.close(); } return sbuilder.toString(); }   /** * read a file and converting it to String using StringWriter */ public ...

Install Tomcat 7 on CentOS, RHEL, or Fedora

Install Tomcat 7 on CentOS, RHEL, or Fedora This post will cover installing and basic configuration of Tomcat 7 on CentOS 5.x. or CentOS 6.x Tomcat 7 implements the JavaServer Pages 2.2 and Servlet 3.0 specifications and a number of new features. The Manager application also has a new look and finer-grain roles and access than 6.x In this post, we'll install Tomcat 7, the new JDK 7, configure Tomcat as a service, create a start/stop script, and (optionally) configure Tomcat to run under a non-root user. We will also configure basic access to Tomcat Manager and take a quick look at memory management using JAVA_OPTS Finally, we will look at running Tomcat on port 80 as well as some strategies for running Tomcat behind Apache. I have just updated this post with Tomcat 7.0.29, the current stable release of Tomcat 7. If you are using a different release, simply change the file names below accordingly. To begin, we'll need to install the Java Development Kit (J...