
how to open and view a flat file in browser using java code in jsp?

Hi Friend,
If you want to simply open a file then try the following code:
<%@page import="java.util.*"%>
<%
Runtime rt = Runtime.getRuntime();
rt.exec("cmd.exe /C start C:/data.txt");
%>
If you want to read the file,
<%@page import="java.io.*"%>
<%
FileInputStream fstream = new FileInputStream(new File("C:/data.txt"));
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str;
while ((str = br.readLine()) != null) {
out.println(str);
}
%>

Dear friend,
<%@page import="java.util.*"%>
<% Runtime rt = Runtime.getRuntime(); rt.exec("cmd.exe /C start C:/data.txt");
%>
The mentioned code works fine. But the if the file name is "D:/Interface work/data.txt", its not accepting. The " "(space) in the path creates the problem. Any solution is appreciated.
Thanks in advance.

Dear friend,
<%@page import="java.util.*"%>
<% Runtime rt = Runtime.getRuntime(); rt.exec("cmd.exe /C start C:/data.txt");
%>
The mentioned code works fine. But the if the file name is "D:/Interface work/data.txt", its not accepting. The " "(space) in the path creates the problem. Any solution is appreciated.
Thanks in advance.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.