Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3453774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:24:51+00:00 2026-05-18T09:24:51+00:00

In the below code the questions, answers i enter in jsp form are entered

  • 0

In the below code the questions, answers i enter in jsp form are entered in text file. But infront of it number must be printed

<%@ page language="java" import="java.io.*" errorPage="" %>
<%

         /* String num=request.getParameter("qnum");
    session.setAttribute("quesnum",num);*/

    String q=request.getParameter("qn");
    session.setAttribute("question",q);

    String opt1=request.getParameter("A");
    session.setAttribute("a",opt1);

    String opt2=request.getParameter("B");
    session.setAttribute("b",opt2);

    String opt3=request.getParameter("C");
    session.setAttribute("c",opt3);

    String opt4=request.getParameter("D");
    session.setAttribute("d",opt4);

    String ans=request.getParameter("ANS");
    session.setAttribute("answer",ans);


%>

<html>
<head>
<title>Text File</title>
</head>

<body>
<%



File f=new File("D:\\Program Files\\Tomcat 6.0\\webapps\\ROOT\\tst.txt");
f.createNewFile();
try
{

BufferedWriter bw=new BufferedWriter(new FileWriter(f,true));

    int num=1;

   bw.newLine();
 while(num<100)
   {  

        bw.write((char)num);
        bw.write("|");
    bw.write(q);

        bw.write("|");
    bw.write(opt1);

        bw.write("|");
    bw.write(opt2);

        bw.write("|");
    bw.write(opt3);

        bw.write("|");
    bw.write(opt4);

        bw.write("|");
        bw.write(ans);

        bw.flush();


bw.close();
}

num++;
}
catch(Exception e)
{
}
%>

</body>
</html>

Output must be 
1|quest1|option a |option b|option c|option d| and:a
2|quest2|option a |option b|option c|option d| and:b
3|quest3|option a |option b|option c|option d| and:d

but instead of 1 2 3 i get 
 []|quest1|option a |option b|option c|option d| and:a

[] symbol is coming in text file. Whats the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:24:52+00:00Added an answer on May 18, 2026 at 9:24 am

    You are casting the intnumbers from 1 to 100 to char as byte-values. This is probably not what you want, because this is – assuming western languages – equivalent to the ASCII table from the beginning on. The first 32 or so characters are non-printable stuff like Linefeeds, Beeps etc. which apparently do not make it into your output.

    So instead of

    bw.write((char)i);
    

    you need to convert your int into a String, e. g. like so:

    bw.write(String.valueOf(i));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my javascript and form code where it appends a question number (qnum)
I've got a simple question but it has got me confounded. The code below
Edit: original question below, but I revise it now that I have some code
$('td.qid').text(). The code above will determine which row the alert is refering to. Below
I want to rewrite the following code with the code below, but I am
I've found similar posts, but no clear answers to my questions about strtok_r .
I am using Polymorphic Models . Simple Question: My code below works without using
My code below is supposed to display each question ($_POST[questionText]). For each question, it
I have a basic PHP question, take the code below for example, let's say
Ok another question in VHDL. Below is my code. Suppose that I want my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.