Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

showing contents of a file

Posted on 2007-03-29
13
Medium Priority
?
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 200 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

610 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