Skip to main content
Post Closed as "too localized" by home, UmNyobe, mah, Edwin de Koning, BNL
Rollback to Revision 5; Post Made Community Wiki
Source Link
Emil
  • 7.3k
  • 18
  • 81
  • 135

pleasePlease help check the code.Only Only I the beginner can write the corrected code.

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;   public class servlet extends HttpServlet {   private static final long serialVersionUID = 1L;   public static List<String> getFileNames(File directory, String extension) {   List<String> list = new ArrayList<String>();   File[] total = directory.listFiles();   for (File file : total) {   if (file.getName().endsWith(extension)) {   list.add(file.getName());   }   if (file.isDirectory()) {   List<String> tempList = getFileNames(file, extension);   list.addAll(tempList);   }   }   return list;  } @SuppressWarnings("resource")    protected void doPost(HttpServletRequest request, HttpServletResponse response)   throws ServletException, IOException   {    request.setCharacterEncoding("utf8");   String myName = request.getParameter("text");   List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt");   for (String string : files) {   if (myName.equals(string)) {   try {   File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string);   FileReader reader = new FileReader(file);   int b;   PrintWriter writer = response.getWriter();   writer.print("<html>");   writer.print("<head>");   writer.print("<title>HelloWorld</title>");   writer.print("<body>");   writer.write("<div>");   while((b = reader.read()) != -1) {   writer.write((char) b);   }   writer.write("</div>");   writer.print("</body>");   writer.print("</html>");   }   catch (Exception ex) {   System.exit(0);   }   }   }  } } 

The error may be here:

catch (Exception ex) {   System.exit(0); } 

andAnd here:

please help check the code.Only I the beginner can write the corrected code

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;   public class servlet extends HttpServlet { private static final long serialVersionUID = 1L; public static List<String> getFileNames(File directory, String extension) { List<String> list = new ArrayList<String>(); File[] total = directory.listFiles(); for (File file : total) { if (file.getName().endsWith(extension)) { list.add(file.getName()); } if (file.isDirectory()) { List<String> tempList = getFileNames(file, extension); list.addAll(tempList); } } return list; }   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  { request.setCharacterEncoding("utf8"); String myName = request.getParameter("text"); List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt"); for (String string : files) { if (myName.equals(string)) { try { File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string); FileReader reader = new FileReader(file); int b; PrintWriter writer = response.getWriter(); writer.print("<html>"); writer.print("<head>"); writer.print("<title>HelloWorld</title>"); writer.print("<body>"); writer.write("<div>"); while((b = reader.read()) != -1) { writer.write((char) b); } writer.write("</div>"); writer.print("</body>"); writer.print("</html>"); } catch (Exception ex) { System.exit(0); } } } } 

The error may be here

catch (Exception ex) { System.exit(0); } 

and here

Please help check the code. Only I the beginner can write the corrected code.

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class servlet extends HttpServlet {   private static final long serialVersionUID = 1L;   public static List<String> getFileNames(File directory, String extension) {   List<String> list = new ArrayList<String>();   File[] total = directory.listFiles();   for (File file : total) {   if (file.getName().endsWith(extension)) {   list.add(file.getName());   }   if (file.isDirectory()) {   List<String> tempList = getFileNames(file, extension);   list.addAll(tempList);   }   }   return list;  } @SuppressWarnings("resource")  protected void doPost(HttpServletRequest request, HttpServletResponse response)   throws ServletException, IOException {    request.setCharacterEncoding("utf8");   String myName = request.getParameter("text");   List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt");   for (String string : files) {   if (myName.equals(string)) {   try {   File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string);   FileReader reader = new FileReader(file);   int b;   PrintWriter writer = response.getWriter();   writer.print("<html>");   writer.print("<head>");   writer.print("<title>HelloWorld</title>");   writer.print("<body>");   writer.write("<div>");   while((b = reader.read()) != -1) {   writer.write((char) b);   }   writer.write("</div>");   writer.print("</body>");   writer.print("</html>");   }   catch (Exception ex) {   System.exit(0);   }   }   }  } } 

The error may be here:

catch (Exception ex) {   System.exit(0); } 

And here:

Pleaseplease help check the code. OnlyOnly I the beginner can write the corrected code.

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;   public class servlet extends HttpServlet {   private static final long serialVersionUID = 1L;   public static List<String> getFileNames(File directory, String extension) {   List<String> list = new ArrayList<String>();   File[] total = directory.listFiles();   for (File file : total) {   if (file.getName().endsWith(extension)) {   list.add(file.getName());   }   if (file.isDirectory()) {   List<String> tempList = getFileNames(file, extension);   list.addAll(tempList);   }   }   return list;  } @SuppressWarnings("resource")    protected void doPost(HttpServletRequest request, HttpServletResponse response)   throws ServletException, IOException   {    request.setCharacterEncoding("utf8");   String myName = request.getParameter("text");   List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt");   for (String string : files) {   if (myName.equals(string)) {   try {   File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string);   FileReader reader = new FileReader(file);   int b;   PrintWriter writer = response.getWriter();   writer.print("<html>");   writer.print("<head>");   writer.print("<title>HelloWorld</title>");   writer.print("<body>");   writer.write("<div>");   while((b = reader.read()) != -1) {   writer.write((char) b);   }   writer.write("</div>");   writer.print("</body>");   writer.print("</html>");   }   catch (Exception ex) {   System.exit(0);   }   }   }  } } 

The error may be here:

catch (Exception ex) {   System.exit(0); } 

Andand here:

Please help check the code. Only I the beginner can write the corrected code.

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class servlet extends HttpServlet {   private static final long serialVersionUID = 1L;   public static List<String> getFileNames(File directory, String extension) {   List<String> list = new ArrayList<String>();   File[] total = directory.listFiles();   for (File file : total) {   if (file.getName().endsWith(extension)) {   list.add(file.getName());   }   if (file.isDirectory()) {   List<String> tempList = getFileNames(file, extension);   list.addAll(tempList);   }   }   return list;  } @SuppressWarnings("resource")  protected void doPost(HttpServletRequest request, HttpServletResponse response)   throws ServletException, IOException {    request.setCharacterEncoding("utf8");   String myName = request.getParameter("text");   List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt");   for (String string : files) {   if (myName.equals(string)) {   try {   File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string);   FileReader reader = new FileReader(file);   int b;   PrintWriter writer = response.getWriter();   writer.print("<html>");   writer.print("<head>");   writer.print("<title>HelloWorld</title>");   writer.print("<body>");   writer.write("<div>");   while((b = reader.read()) != -1) {   writer.write((char) b);   }   writer.write("</div>");   writer.print("</body>");   writer.print("</html>");   }   catch (Exception ex) {   System.exit(0);   }   }   }  } } 

The error may be here:

catch (Exception ex) {   System.exit(0); } 

And here:

please help check the code.Only I the beginner can write the corrected code

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;   public class servlet extends HttpServlet { private static final long serialVersionUID = 1L; public static List<String> getFileNames(File directory, String extension) { List<String> list = new ArrayList<String>(); File[] total = directory.listFiles(); for (File file : total) { if (file.getName().endsWith(extension)) { list.add(file.getName()); } if (file.isDirectory()) { List<String> tempList = getFileNames(file, extension); list.addAll(tempList); } } return list; }   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  { request.setCharacterEncoding("utf8"); String myName = request.getParameter("text"); List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt"); for (String string : files) { if (myName.equals(string)) { try { File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string); FileReader reader = new FileReader(file); int b; PrintWriter writer = response.getWriter(); writer.print("<html>"); writer.print("<head>"); writer.print("<title>HelloWorld</title>"); writer.print("<body>"); writer.write("<div>"); while((b = reader.read()) != -1) { writer.write((char) b); } writer.write("</div>"); writer.print("</body>"); writer.print("</html>"); } catch (Exception ex) { System.exit(0); } } } } 

The error may be here

catch (Exception ex) { System.exit(0); } 

and here

deleted 28 characters in body
Source Link
Emil
  • 7.3k
  • 18
  • 81
  • 135

pleasePlease help check the code.Only Only I the beginner can write the corrected code.

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class servlet extends HttpServlet {   private static final long serialVersionUID = 1L;   public static List<String> getFileNames(File directory, String extension) {   List<String> list = new ArrayList<String>(); File[] total = directory.listFiles(); for (File file : total) { if (file.getName().endsWith(extension)) { list.add(file.getName()); } if (file.isDirectory()) { List<String> tempList = getFileNames(file, extension); list.addAll(tempList); } } return list; }   @SuppressWarnings("resource") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf8"); String myName = request.getParameter("text");   List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt"); for (String string : files) { if (myName.equals(string)) { try { File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string); FileReader reader = new FileReader(file); int b; PrintWriter writer = response.getWriter(); writer.print("<html>"); writer.print("<head>"); writer.print("<title>HelloWorld</title>"); writer.print("<body>"); writer.write("<div>"); while((b = reader.read()) != -1) { writer.write((char) b); } writer.write("</div>"); writer.print("</body>"); writer.print("</html>"); } catch (Exception ex) { System.exit(0); } } } } } 

The error may be here:

andAnd here:

 FileReader reader = new FileReader(file); 

please help check the code.Only I the beginner can write the corrected code

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class servlet extends HttpServlet {   private static final long serialVersionUID = 1L;   public static List<String> getFileNames(File directory, String extension) {   List<String> list = new ArrayList<String>(); File[] total = directory.listFiles(); for (File file : total) { if (file.getName().endsWith(extension)) { list.add(file.getName()); } if (file.isDirectory()) { List<String> tempList = getFileNames(file, extension); list.addAll(tempList); } } return list; }   @SuppressWarnings("resource") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf8"); String myName = request.getParameter("text");   List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt"); for (String string : files) { if (myName.equals(string)) { try { File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string); FileReader reader = new FileReader(file); int b; PrintWriter writer = response.getWriter(); writer.print("<html>"); writer.print("<head>"); writer.print("<title>HelloWorld</title>"); writer.print("<body>"); writer.write("<div>"); while((b = reader.read()) != -1) { writer.write((char) b); } writer.write("</div>"); writer.print("</body>"); writer.print("</html>"); } catch (Exception ex) { System.exit(0); } } } } } 

The error may be here

and here

 FileReader reader = new FileReader(file); 

Please help check the code. Only I the beginner can write the corrected code.

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class servlet extends HttpServlet { private static final long serialVersionUID = 1L; public static List<String> getFileNames(File directory, String extension) { List<String> list = new ArrayList<String>(); File[] total = directory.listFiles(); for (File file : total) { if (file.getName().endsWith(extension)) { list.add(file.getName()); } if (file.isDirectory()) { List<String> tempList = getFileNames(file, extension); list.addAll(tempList); } } return list; } @SuppressWarnings("resource") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf8"); String myName = request.getParameter("text"); List<String> files = getFileNames(new File("C:\\Users\\vany\\Desktop\\test"), "txt"); for (String string : files) { if (myName.equals(string)) { try { File file = new File("C:\\Users\\vany\\Desktop\\test\\" + string); FileReader reader = new FileReader(file); int b; PrintWriter writer = response.getWriter(); writer.print("<html>"); writer.print("<head>"); writer.print("<title>HelloWorld</title>"); writer.print("<body>"); writer.write("<div>"); while((b = reader.read()) != -1) { writer.write((char) b); } writer.write("</div>"); writer.print("</body>"); writer.print("</html>"); } catch (Exception ex) { System.exit(0); } } } } } 

The error may be here:

And here:

FileReader reader = new FileReader(file); 
deleted 429 characters in body
Source Link
J. Steen
  • 15.6k
  • 15
  • 59
  • 64
Loading
Loading
added 271 characters in body
Source Link
Subhrajyoti Majumder
  • 41.3k
  • 13
  • 84
  • 103
Loading
Source Link
Loading