Wrox Programmer Forums
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2003, 04:34 PM
Registered User
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default reading files

Hi,

I'm new to JSP, although I have quite a bit of experience with Java. I wrote a little program that, when provided with a name, it looks for the listing in a file, and prints out the associated line in the file. For example, if I type in 'John' and click submit, it should take that name, give it the program, and in return get something like '32: John Smith student' if that was the appropriate line in the file.

I wrote this as an applet before, which works fine. However, when I tried doing this using an associated Java program, it opens the file, but then does not read anything. My code is below:

Code:
        section = section.trim();
        student = student.trim();
        String fName = "quizMarks" + section + ".txt";

        info = "got the info";

        try {
            info = "entered loop";
            BufferedReader br = new BufferedReader(new FileReader(fName));

            info = "opened reader";
            String info = br.readLine();
            info = "replaced";
            String grade = br.readLine();
            grade = "replaced";

            while (grade != null) {
                if (grade.indexOf(student) != -1) {
                    break;
                } else { 
                    grade = br.readLine();
                }
            }

            br.close();
            if (grade.indexOf(student) == -1) {
                grade = "There is no record for you in this section";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
I'm based out of DOS right now, so permissions can't be the answer. And the changing of what info is just lets me check where the error is occurring. It happens at the first time it says 'br.readLine();'








Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading large files ravichandrae Pro Java 1 January 11th, 2008 04:42 AM
Reading text files senthilreddy ASP.NET 2.0 Basics 1 May 22nd, 2007 08:32 AM
Reading files from thumbdrive. karatekarthi Java Basics 2 May 16th, 2007 08:25 AM
Reading from Excel Files interrupt Javascript How-To 8 September 28th, 2006 09:31 AM
Reading .ini files anisurr C++ Programming 2 February 7th, 2006 05:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.