Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

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.
0
megakingbob
Asked:
megakingbob
  • 5
  • 3
1 Solution
 
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
 
TimYatesCommented:
<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
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.

 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now