View RSS Feed

My Java Tips

  1. 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 package.

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

    Java Code:
    Java SE
  2. 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="*"  %>
    String str = "form data goes here";