Solved

Importing .txt files

Posted on 2004-04-23
9
280 Views
Last Modified: 2010-04-01
I am trying to import .txt files using jsp, i have created a table and want one each in each cell, i'm not sure of the commands i need to import them, and also to save them again (which will be needed later) thanks.
0
Comment
Question by:megakingbob
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10898149
are you talking about a jtable? or a database table?

what is in the textfile? is it delimited records? or will it need to be parsed?
0
 

Author Comment

by:megakingbob
ID: 10898211
just a <table> in a webpage, it's just text no parsing is necessary.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 10898248
<table>
  <tr>
    <td>

<%
    java.io.BufferedReader br = null ;
    try
    {
        br = new java.io.BufferedReader( new java.io.FileReader( "/files/text.txt" ) ) ;
        String line ;
        while( ( line = br.readLine() ) != null )
            out.println( line ) ;
    }
    catch( java.io.IOException ex )
    {
        out.println( ex.toString() ) ;
    }
    finally
    {
        try { if( br != null ) br.close() ; } catch( java.io.IOException ex ) {}
    }
%>

    </td>
  </tr>
</table>
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 35

Expert Comment

by:TimYates
ID: 10898254
Assuming your text file is on the server in the "/files" directory (off the root)
0
 

Author Comment

by:megakingbob
ID: 10898346
it works but can i use relative addressing instead of fixed for the location of the text file.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10898494
You need to work out what the current working directory is...

try

<%
  out.println( "CWD: " + new java.io.FIle( "." ).getAbsolutePath() ) ;
%>

That should show you the working directory, then relative directories should be able to be used relative to that...

I hope ;)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10898560
FIle

should be

File

of course :)
0
 

Author Comment

by:megakingbob
ID: 10898657
thanks very much, its only because its going onto another server but i'll alter it again when it's on that server with the help you provided thanks again :-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10898668
:-)  Hope it works!  (It should do)

Good luck with it!!

Tim
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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