Solved

showing contents of a file

Posted on 2007-03-29
13
149 Views
Last Modified: 2010-03-31
hi all

is it possible to show the contents within a file?

e.g. i have a .vm file, i want to get the .vm files content and show them

is anyone able to lead me to an example

any help much appreciated

0
Comment
Question by:dalecon
13 Comments
 
LVL 4

Expert Comment

by:MikeGeig
ID: 18816315
Hello,

What type of file is a .vm?
0
 

Author Comment

by:dalecon
ID: 18816327
velocity template

just contains html type code
0
 

Author Comment

by:dalecon
ID: 18816425

no worries got it
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:dalecon
ID: 18817417
oh well, spoke too soon
i'm using this and can read the ocntents of my file

FileInputStream fis = new FileInputStream("a.vm");                  
InputStreamReader isr = new InputStreamReader(fis,"UTF8");                  
Reader in = new BufferedReader(isr);                  
int ch;            
while ((ch = in.read()) > -1)
{
stringbuffer.append((char)ch);
}

however when i display the file contents in my broswer it displays it as an html page, i just want it shown as plain text,

can anyone show me how i can display the contents of the .vm file just as palin text without the broswer formatting it back to an html page?

many thanks
0
 
LVL 3

Expert Comment

by:cavey_79
ID: 18817473
If you're using servlets, on your response object you need to call response.setContentType("text/plain")

For jsps, you would use this:
<%@ page contentType="text/plain"%>

If you have other html stuff in your page and want the page to still be an html, but this text to be displayed as it is, you will need to escape it. There are several ways to do that, let me know if you need it.

If you're just opening the file with a browser, there's not much you can do. Easiest way would probably be to generate an escaped version of the file.
0
 

Author Comment

by:dalecon
ID: 18817528


do you have an example of escaping the file ?

many thanks for your help
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18818713
>> when i display the file contents in my broswer it displays it as an html page

The code that you posted - is it reading the file in a servlet and then printing the contents using out.println () ?
0
 
LVL 3

Expert Comment

by:cavey_79
ID: 18818903
If you do it in a jsp, you could just do it with <c:out value="${yourVarHere}" />. If you use a servlet, you just need to do these kind of replaces:
& to &amp;
< to &lt;
> to &gt;

Assuming you have a huge String, in JDK5 you would do print(yourString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;"));
0
 

Author Comment

by:dalecon
ID: 18822124
i have this in my jsp

<jsp:useBean id="template" class="com.utils.getstuff">
<jsp:setProperty name="template" property="*"/>
<%
contents = template.getContents();                        
%>
</jsp:useBean>

<td><%=contents %></td>
0
 

Author Comment

by:dalecon
ID: 18822203


think i've orted it
0
 
LVL 3

Accepted Solution

by:
cavey_79 earned 50 total points
ID: 18823573
Replace this
<td><%=contents %></td>
with this
<td><%=contents.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;") %></td>

I assume contents is a String. If not, replace it with
<td><%=contents.toString().replace("&","&amp;").replace("<","&lt;").replace(">","&gt;") %></td>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 106
Android development question 2 54
pagenation logic how it is working in my code 1 56
Java syntax, or is it Selenium 6 30
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question