View RSS Feed

Recent Blogs Posts

  1. How to use properties file in Java

    by , 02-29-2012 at 10:57 AM
    Software programs may need to store its settings or configuration in a file on disk, such as database connection settings or user preferences. In Java, it is possible to use some classes in the java.io package such as FileReader and FileWriter to read/write the configuration file. However, that approach is tedious and error-prone, because it requires writing a lot of code from scratch. Fortunately, the Java platform provides an out-of-the-box utility class which is designed specifically for that ...
    Categories
    Properties
  2. How to work zip files in Java

    by , 02-29-2012 at 09:59 AM
    he Java platform provides powerful API to work with the most popular compressed file format zip format. This article will show you how to write code to compress and decompress zip files using Java. And beyond the basics, the code that works with multiple files in a directory recursively is also provided.

    The Zip API

    The package java.util.zip provides classes for working with zip file format. Although the documentation states that the package also provides classes ...
    Tags: file, java, zip Add / Edit Tags
    Categories
    Zip
  3. How to write a Servlet that sends file to user to download

    by , 12-10-2011 at 05:54 AM
    Downloading files is a very popular task on the World Wide Web. Users click on a download link and the file gets downloaded into their computer. Technically, a download can be achieved by either of the two forms as following:

    • Direct link: the link points directly to a file on a server, for example: http://www.server.com/download/report.xls. This kind of link requires no additional effort on the server side, since the web server automatically hands the file over to users as
    ...
    Categories
    Servlet , File
  4. How to write a Servlet that uploads file to server

    by , 12-10-2011 at 05:19 AM
    Uploading files is a common operation for internet applications. Doing so in Java is pretty simple. This article will guide you through some steps to write a Java servlet that uploads a file then store it on the server.
    Before going on, this article assumes that you have some Java web development experience, you are be able to use Eclipse IDE to write the code and deploy a web application on Tomcat 6.0 server.
    The web application we are going to build contains the following components: ...
    Tags: file, servlet, upload Add / Edit Tags
    Categories
    Servlet , File
  5. Reading an ASCII file (BufferedReader)

    by , 11-10-2011 at 06:14 PM (My Java Tips)
    Normally we give input to Java applications from command prompt or through GUI. But sometimes, when inputs are in bulk, we can use ASCII files for input. Such files must have some agreed upon pattern so Java parser can understand the meaning of the text. There are many ways to read a file but one of the simplest way is to use BufferedReader class which is found in java.io package.


    First prompt the user to enter the file name with path. This can be done using:

    Java Code:
      
    ...
    Categories
    Java SE
  6. Writing a file from JSP

    by , 05-24-2011 at 02:45 PM (My Java Tips)
    You may want to write a file from JSP page. For example, user fills a form and you want to persist the details on a text file on server. Now you need to know how to write text file from JSP.

    Remember, always give the path from root. In the given snippet, nameOfTextFile contains the file path. We will use FileOutputStream to write to the file.

    Java Code:
    <%@ page import="java.io.*"  %>
    <%
    String str = "form data goes here";
    ...
    Categories
    JSP