Display the content of a text file in a browser
I am new to servlet, I have written a java servlet code which can read a file and display its content in command prompt only(resin),i would like to ask how can i display the content on the browser and i also want to ask how to write a servlet which can display the conetent from a web browser( e.g. whatever i type in a form) and produce the result in the text file.
import java.io.FileReader;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
public class read extends HttpServlet
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
String applicationPath =
getServletContext().getRealPath ("");
String filePath =
getServletContext().getRealPath ("/WEB-INF/text.txt");
FileReader fr = new FileReader (filePath);
for (int chr = fr.read(); chr != -1; chr = fr.read())
System.out.print ((char) chr);
}
You have to create an object of PrintWriter and use that to display the output on the browser.
PrintWriter out = response.getWriter();
out.println(chr);
Hope this helps..
Arun
Similar Messages
-
Want to display the contents of a text file in a jsp
hi
i am new to jsp, i want to display the contents of a text file in a jsp file ,whenever jsp file is loaded from browser.
-thanxi had come up with the code
<!-- form.jsp -->
<%@ page import="java.io.*, java.lang.*" %>
<%@ page language="java" %>
<html>
<head>
<title>Display</title>
</head>
<body>
<%
String sample[100];
String line;
%>
<%! int i=0; %>
<%!File f1 = new File("c:\\file.txt"); %>
<% try { %>
<%!FileReader fi = new FileReader(f1); %>
<% } catch(FileNotFoundException io) { } %>
<%!BufferedReader in = new BufferedReader(fi); %>
<%
while((line=in.readLine())!= null)
sample= line;
i++;
in.close();
%>
i will display sample here
</body>
</html>
but i am getting error
display_jsp.java:16: unreported exception java.io.FileNotFoundException;
must be caught or declared to be thrown
FileReader fi = new FileReader(f1);
^
plz help
-thanx -
How to display the contents of a text file on the command line?
I realize I need to utilize classes from the java.io.* package, but I don't know which ones to use exactly. This is what I would like to do in a nutshell:
public static void main(String[] args) throws IOException {
File inputFile = new File( <path to the file>);
// code that reads data from the above file and is able to
// append it to a string object or display it on the command
// line (System.out.println)
}Thanks for your time!It's pretty easy. Here's a little example that reads a file, stores it in a string, and prints it to the command line.
import java.io.*;
public class OpenFile {
public static void main(String args[]) {
try {
File fileToOpen = new File("something.txt");
FileReader fileIn = new FileReader(fileToOpen);
BufferedReader br = new BufferedReader(fileIn);
String fileContent = new String();
String line;
while ((line = br.readLine()) != null) {
fileContent += line + "\n";
System.out.println(fileContent);
br.close();
catch (IOException e) {
System.out.println("Exception: " + e);
}Good luck,
Alex -
We have a Content Presenter taskflow. This task flow is added to a jspx page. The taskflow fetches the content from the contributor data file. The contributor data file is having a WYSIWYG editor. The content of the WYSIWYG editor is being displayed correctly through the task flow.
We have some links in the WYSIWYG editor. These links again point to some data files. When we click on these links from within the portal, then we are getting a blank page(the url of this blank page is: http://localhost:7101/eWSIBPortal/faces/oracle/webcenter/sitestructure/render.jspx?datasource=UCM%23dDocName%3AWSIB_ARTICLE) and not displaying the content of the data file that we are pointing to from the WYSIWYG editor.
We want to display the content of these data files(which we have pointed from WYSIWYG editor) in-line within the portal.
Please help us to resolve this issue and let us know if any information is required from our end.Thanks for reply. However, can I use XSQL to dump the formated text to a file? or just can display to client through web browsers?
-
Can we Read/Display the content of Word/PDF file in Flex 3/4 ?
Hello All,
Can we read/display the content of Word/PDF file in Flex 3 or Flex 4?. I have one word file containing Arabic and English content with some settings like Bold, Color, Align etc. I want to display the content of this word file as it is in the flex web application.
Awaiting for prompt reply.
Thanks and Regardsthank you for your immediate reply, but,
sorry, this does not work.
With this code:
<cfpdf action = "read" source = "dok_1.pdf" name =
"mypdf">
<cfdump var="#mypdf#"/>
I get this result:
Everything, but no text of the document.
PDFDocument
Application name of application
Author bimbam Verlag GmbH
CenterWindowOnScreen [empty string]
ChangingDocument Allowed
Commenting Allowed
ContentExtraction Allowed
CopyContent Allowed
Created D:20080710
DocumentAssembly Allowed
Encryption No Security
FilePath [empty string]
FillingForm Allowed
FitToWindow [empty string]
HideMenubar [empty string]
HideToolbar [empty string]
HideWindowUI [empty string]
Keywords [empty string]
Language [empty string]
Modified [empty string]
PageLayout SinglePage
Printing Allowed
Producer [empty string]
Properties [empty string]
Secure Allowed
ShowDocumentsOption [empty string]
ShowWindowsOption [empty string]
Signing Allowed
Subject [empty string]
Title Rheinische Angler-Zeitschrift
TotalPages 1
Trapped [empty string]
Version 1.3
Maybe i do not understand the cfpdf tag the right way.
What i want is a kind of pdf-to-text conversion.
Do I have to use the processddx action? I do not think so.
But there is a property DocumentText .. ? -
How to read the content of a text file (by character)?
Guys,
Good day!
I'm back just need again your help. Is there anyone knows how to read the content of a text file not by line but by character.
Please help me. Thank you so much in advance.
Jojohttp://java.sun.com/javase/6/docs/api/index.html
package java.io
InputStream.read(): int
Reads the next byte of data from the input stream.
Implementation:
InputStreamReader
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted. -
How to store the contents of a text file directly in to a clob field
Hi All,
Could anyone help me to store the contents of a text file (*.txt,*.xml etc)directly in to a clob field.
Thanks in advance
Jayaram.One way is to use sqlloader. Three files are used. A control file, an xml data file, and a file with the path of the xml data file. Here's the control file. It reads load.file, which is the file with the path of the xml data file. It names the path ext_path, and inserts the xml into field xml_field.
CONTENTS OF CONTROL FILE:
load DATA
INFILE 'load.file'
APPEND
INTO TABLE xml_table
( ext_path FILLER CHAR(13),
"XML_FIELD" LOBFILE(ext_fname) TERMINATED BY EOF
CONTENTS OF FILE LOAD.FILE:
/tmp/load.dat
The xml is in the file /tmp/load.dat.
null -
I want to read the content of a text file dropped in a watched folder into a string variable
I have a workbench process with 2 variable.
inDoc (DataType=Document/input/required)
outStr (DataType = String/output)
The document being passed to the workflow is a text file with 4 lines of text in it. when the text file is dropped into the watched folder, it will be assigned to the inDoc parameter in the workflow.
My workflow needs to extract the 4 lines of text and write it into a string (outStr).
Id like to use the FileUtilsService.ReadString service but i can't since its input parameter is the file path. When i do, i get the following error...
Caused by: ALC-FUT-001-011: File rO0ABXNyABZjb20uYWRvYmUuaWRwLkRvY3VtZW50yAEFUxsO+CEDACNJAAtfY2FsbGJhY2tJZFoADV9kZXNlcmlhb Gl6ZWRJABBfZ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9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAA AADdAAKd3NmaWxlbmFtZXQAJ0M6XFVzZXJzXENodWxseS5QYXJrXERlc2t0b3BcaGRzY2FuLnR4dHQACGJhc2VuYW1 ldAAKaGRzY2FuLnR4dHQABGZpbGVxAH4AFXh3NwAtYWRvYmUvaWRwL0RvY3VtZW50UHVsbFNlcnZhbnQvYWRvYmVqY l9MQ19ERVYx//////////94 does not exist.
at com.adobe.livecycle.fileutils.FileUtilsService.readDocument(FileUtilsService.java:363)
which is what i expected...
I've also tried with the Script.executeScript to call some java code but im not too strong in java and in all the examples i find, the file pointer requires a file path.
import java.io.*;
FileInputStream f = new FileInputStream(patExecContext.getProcessDataValue("/process_data/inDoc"));
OR
File f = new File(patExecContext.getProcessDataValue("/process_data/inDoc"));
OR
File f = patExecContext.getProcessDataValue("/process_data/inDoc");
Any clue how to resolve my problem?Try the following code snippet to read the String content from the file recieved through watched folder endpoint.
com.adobe.idp.Document inputDoc = patExecContext.getProcessDataDocumentValue("/process_data/inDoc");
java.io.InputStream inStream = inputDoc.getInputStream();
byte[] dataBuffer = new byte[inStream.available()];
inStream.read(dataBuffer);
String strData = new String(dataBuffer);
patExecContext.setProcessDataStringValue("/process_data/outStr",strData);
The code is not tested, hence if you find any mistakes, correct and test the functionality.
Nith -
How to read the contents of a text file and populate the data in a table ?
Hello All,
Can anyone advise on how to acheieve the above ? I am trying to read in a text file (CSV) and have the contents populated to the respective UI elements in a table. Any help is greatly appreciated.
from
Kwok WeiHi,
Let us consider you have list of names(Seperated by delimeter) in a text file and you want to display in a table.
1. Create Context Node "Names" and context attribute "Name"
2. Create Table and bind to the above context.
3.Write the following code in the "Init method.
try{
FileReader f =new FileReader("");
BufferedReader r=new BufferedReader(f);
String names=r.readLine();
Vector Names=new Vector();
// Use Tokenizer and store all the names i a vector//
for(int i=0;i<Names.size();i++){
IPrivate<<VieName>>.INameElement ele=wdContext.createNameElement();
ele.set<<Name>>( Names.get(i).toString());
wdContext.NodeName().addElement(ele);
Regards, Anilkumar
Message was edited by: Anilkumar Vippagunta -
How to modify the contents of a text file stored along with a midlet
Hi,
I have been developing a application in j2me wherein i need to first read the contents of the text file stored along with the midlet and later erase the existing content and update it with some text.
I was able to read the file in the following manner
InputStream is = getClass().getResourceAsStream("myfile.txt");
Now i need to erase the contents and then update it the new content, how do i do it. Kinldy please help me out. It is very urgent.
ThanksDidn't you hear me the first time?
http://forum.java.sun.com/thread.jspa?threadID=701360&messageID=4068435#4068435 -
How to check the content in a text file line
hi all,
i had the following problem:
There is a text file with multiple lines of data in it
The data comprises of characters, numbers and symbols
In this file, any line can be commented (till the end) by using symbol ';'(semi-colon)
Now i have to find the number of occurences of a symbol '$' in this data, such that
it should not exist in a commented line
One more limitation is that ';' (semi-colon) could occur at any position in a line, i.e., if this occured in the middle of the line, then all the following data in the line is taken to be as commented one and we have to skip it and move to next line.
Plz do help.
Regards,
santosh
Regards,
santoshHi santosh,
just a guess this is what you need.
Greets, Dave
Message Edited by daveTW on 09-15-2006 09:59 AM
Greets, Dave
Attachments:
search & count $.vi 13 KB
search & count $.png 10 KB -
Hi I want to display the contents of a xml file.
Hi i dont't know how to read a xml file using DOM parser in java.Can anybody help me out in this the following is the xml file
[=========================================
<MODULE ID="RWORLD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/C:/Projects/RWORLD/RDP_rate.xsd">
<PHONE_TYPE>RIM
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
<PHONE_TYPE>FWP
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
<PHONE_TYPE>PCO
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
<PHONE_TYPE>FWT
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
</MODULE>
===================
I want to read the above file and the output should be in the following format :
======
Phone_Type , RWorld_Type , Rate
RIM L0 3
RIM L1 0
RIM L2 0
FWP L0 3
FWP L1 0
FWP L2 0
PCO L0 3
PCO L1 0
PCO L2 0
FWT L0 3
FWT L1 0
FWT L2 0
======Use an XSLT for the specified format.
-
Displaying contents of a text file in a text box
As the topic describes, I need to display the contents of a
text file in a text box. How would one go about doing this? Thanks
in advance.// setting up the text format options
var FileFormat:TextFormat = new TextFormat ();
FileFormat.font = "Verdana";
FileFormat.size = 12;
FileFormat.align = "left";
FileFormat.color = 0xFFFFFF;
/// load in text from folder load_in , filename is text.txt
var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function (success:Boolean):Void{
if (success){
textfield.text = this.txtVarLoaded;
textfield.setTextFormat ( FileFormat );
} else {
trace ("error");
my_lv.load ("load_in/text.txt"); // load in text.txt
peace ;o) -
Reading from a text file and displaying the contents with in a frame
Hi All,
I am trying to read some data from a text file and display it on a AWT Frame. The contents of the text file are as follows:
pcode1,pname1,price1,sname1,
pcode2,pname2,price2,sname1,
I am writing a method to read the contents from a text file and store them into a string by using FileInputStream and InputStreamReader.
Now I am dividing the string(which has the contents of the text file) into tokens using the StringTokenizer class. The method is as show below
void ReadTextFile()
FileInputStream fis=new FileInputStream(new File("nieman.txt"));
InputStreamReader isr=new InputStreamReader(fis);
char[] buf=new char[1024];
isr.read(buf,0,1024);
fstr=new String(buf);
String Tokenizer st=new StringTokenizer(fstr,",");
while(st.hasMoreTokens())
pcode1=st.nextToken();
pname1=st.nextToken();
price1=st.nextToken();
sname1=st.nextToken();
} //close of while loop
} //close of methodHere goes my problem: I am unable to display the values of pcode1,pname1,price1,sname1 when I am trying to access them from outside the ReadTextFile method as they are storing "null" values . I want to create a persistent string variable so that I can access the contents of the string variable from anywhere with in the java file. Please provide your comments for this problem as early as possible.
Thanks in advance.If pcode1,pname1,price1,sname1 are global variables, which I assume they are, then simply put the word static in front of them. That way, any class in your file can access those values by simply using this notation:
MyClassName.pcode1;
MyClassName.pname1;
MyClassName.price1;
MyClassName.sname1 -
How to display the content of a file in the portal?
Hey guys, could anyone help?
I just created a page which includes two iView, one is KM Navigation iView to display a certain repository, while the other is for displaying the content of a certain file I click in the navigation iView.
And now the problem is when I click a file in the KM Navigation iView, it will pop up a new window to display it. How can I make it displayed in a fixed iView, which type of this iView should be?Hi,
you can try to use the:
<b>ConsumerTreeListPreview</b>
layout for KM navigation ivew (or customize to your own).
This layout shows a folder tree on the left, a document list on the right. When you click on a document from the list it shows the contents of the file on the bottom of the iview.
Hope this helps,
Romano
Maybe you are looking for
-
My MacBook pro refuses to work with my Kodak esp 3.2s?
i have bought a MacBook over a month ago i have got it checked out their are no issues with it what so ever. However the Kodak printer i have tried connecting wireless but still will not work even when i try to use t with a wired connection it still
-
Multiple Idocs (DEBMAS06) into one single file
Hi All, Multiple Idocs(DEBMAS06) are sent from SAP in bulk to be sent to FTP server via XI...(Cannot use Append the file as The structure is with Header,Detail(all the idoc details) and Trailer) I have seen different threads which speaks about the sa
-
What kind of audio filter would i use.
i need an audio filter that will bring out a distant clapping noise thats you cant even hear during playback. i have raised the dB as high as possible. is there a way to get it heard at all?
-
All iPhoto 6 images disapeared
I seem to have a major problem with my image library. I have my library stored on an external FireWire drive. I have about 13000 images in my library (about 8GB). This morning, while downloading 60 some images from my camera, I noticed some images co
-
Love Firefox but it's annoying that if I'm using a search engine (I use lots of subscription legal search databases), when I press the back button all the data I entered in the search boxes has disappeared. I'm sure Firefox didn't use to do that?