help to make such a thing (in the previous answer, I was told that I was poorly explained, and now try to explain poponyatneee) I have a form, just a form, the code it is:
<form action="searchf" method="Post">
<input type="text" name="text" autofocus >
<input type="submit" value="">
</form>
The user enters into this form different file names, such as: index.txt, hello.html (files with duplicate names not, and basically it will txt files). Next, the servlet takes string that the user enters:
String myName = request.getParameter("text");
Continue program called input files looking for the files in the folder, but the fact is that it is necessary to enter index.html program to find the file in the folder, not just index, here’s help to enter the extension was not necessarily trying to do so :
String myNamee = request.getParameter("text");
String myName = myNamee.replaceFirst("[.][^.]+$", "");
It did not work (I will be glad to any replies
Eric Scot
If you need to separate the file extension from the filename, you can do something like this:
I recommend that you test this code outside the context of Servlets. Just create a simple Java program with a main method to search a directory for a file and you can forget the user-input and form info. Just hard code some test data to make sure you know how to look through a directory and your code to handle the filenames is working correctly.
You may find this other stack overflow question helpful for understanding how to serach through a directory for a file.