Solved

Importing .txt files

Posted on 2004-04-23
9
278 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
 
LVL 35

Expert Comment

by:TimYates
ID: 10898254
Assuming your text file is on the server in the "/files" directory (off the root)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
A Short Story about the Best File Recovery Software – Acronis True Image 2017
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now