Solved

Importing .txt files

Posted on 2004-04-23
9
281 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Read our guide on how to survive being on-call.

749 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