Importing .txt files

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.
megakingbobAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TimYatesConnect With a Mentor Commented:
<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
 
jkna_gunnCommented:
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
 
megakingbobAuthor Commented:
just a <table> in a webpage, it's just text no parsing is necessary.
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
TimYatesCommented:
Assuming your text file is on the server in the "/files" directory (off the root)
0
 
megakingbobAuthor Commented:
it works but can i use relative addressing instead of fixed for the location of the text file.
0
 
TimYatesCommented:
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
 
TimYatesCommented:
FIle

should be

File

of course :)
0
 
megakingbobAuthor Commented:
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
 
TimYatesCommented:
:-)  Hope it works!  (It should do)

Good luck with it!!

Tim
0
All Courses

From novice to tech pro — start learning today.