Require to read a flat file(Also the file don't have any extension) through URL deployed in JBoss server, couldn't get that as browser/java is not taking the file as a resource to open.
Got 404 in Browser, and File not Found exception when tried with Java. Below is the java code and exception,
import java.net.*;
import java.io.*;
public class URLTest {
public static void main(String[] args) {
/*Block 1: Reading a file "test.txt" (WITH extension) that works */
try{ System.out.println("Block 1");
URL url1 = new URL("http://localhost:8080/CtxPath/test.txt"); //file test.txt available at WebContent
BufferedReader in = new BufferedReader(new InputStreamReader(url1.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} catch(Exception e) { e.printStackTrace(); }
/* Block 2 : Reading the other one "test" (WITHOUT extension) that throws Exception */
try{ System.out.println("Block 2");
URL url2 = new URL("http://localhost:8080/CtxPath/test"); ////file test also available at WebContent
BufferedReader in = new BufferedReader(new InputStreamReader(url2.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} catch(Exception e) { e.printStackTrace(); }
}
}
Block 1
File content from test.txt read successfully.
Block 2
java.io.FileNotFoundException: http://localhost:8080/CtxPath/test
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1624)
at java.net.URL.openStream(URL.java:1037)
at URLTest.main(URLTest.java:28)
Getting exception on opening URL for the file(test) without extension. The other file with .txt extension(test.txt) that placed in the same location with similar content opens without any issues.
Is there any app specific or server specific config to do for allowing the file without extension to be served?