Reading file with BufferedReader

Hi i have a problem iam trying to make a linked lists, where i read a file and
each word in that file is putt into the list.
but the problem is when i use a while loop and the eadLine() method.
like this
<method >
String word;
try .....
while((word = file.readLine() ) ! =null){
word = file.readLine();
The problem is that readLine() only reads the first word in the file and doesnt make the rest of the list
any suggestions??
here is the rest of the code:
import java.io.*;
class Lister
public static void main(String []args) throws Exception {
          Listene l = new Listene();
          l.initiate(args);
class Listene {
private BufferedReader file;
Listerr list = new Listerr();
public void initiate(String args[]) throws IOException
     String filename =args[0];
     String word;
     try
          file = new BufferedReader(new FileReader(filename));
          while( ( word = file.readLine( ) ) != null ){
          word = file.readLine();
          //System.out.println(word);          
          list.insert(ord);
          shutdown();
     catch (FileNotFoundException e)
          System.out.println("Minila-filen kan ikke �pnes: " + filename);
public void shutdown()
     if (file != null)
          try
               file.close();
          catch (Exception e)
               System.out.println("F�r ikke lukket Minila-filen") ;
class Listerr{
Node liste =null;
Node next;
void insert(Object element){
     if(liste==null){
     liste=new Node(element);
     System.out.println("setter inn element: "+element);
     else{
     Node n = liste;
     while(n.neste!=null){
          n=n.neste;
     n.neste=new Node(element);
     System.out.println("setter inn element: "+n.element);
class Node{
     Object element;
     Node neste;
     public Node(Object element2){
     element=element2;
     neste=null;
}

Hi, I assume you are trying to read WORDs seperated by newline. i.e., each WORD occuring in a newline in the input-file. If that is the case, the code you have written should work perfectly. One reason why it may fail is when the newline character inserted by the input-file editor is not the one as listed by System.getProperty("line.separator");
One small change to your code to avoid redundant calls to BufferFileReader::readline() can be done as follows...
String word = null;
try
while( (word = file.readLine()) != null )
list.inert(word);
catch (IOException  ex)
//System.out.println("Could not read file: " + filename + ex.getMessage());
}

Similar Messages

  • How to read the second line in a .txt file with bufferedReader?

    hi,
    i am not the best in speaking english and programming java :)
    so, just try to make sense of my question:
    Im using a BufferedReader to read a .txt file.
    the .txt file has 5+ different lines, and each line has 6 tokens (separated with ; )
    My java file has 6 textFields and each textfield is filled with one of the 6 different tokens.
    and my problem is:
    I want my buffered reader to read the next line (with 6 new different tokens) by pressing a button.
    if somethings not understandable, just ask :)

    maybe its easier to help me, when i publish my code, so here it is:
    (its my version, without Thof's code. Sorry, but the comments are the most in german)
    /* userdata.java */
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class userdata extends Frame {
    //-----------------------------------KlassenVariablen------------------------------------------------
    private JPanel panel = new JPanel ();
    String tokId = "";
    String tokName= "";
    String tokAge= "";
    String tokTel= "";
    String tokMail= "";
    String tokText= "";
    BufferedReader br;
    String zeile;
    StringTokenizer st;
    String delim = ";";
    //---------Buttons f?r Panel 1-------------------------
    Button first = new Button("|< First");
    Button back = new Button("< Back");
    Button next = new Button("Next >");
    Button last = new Button("Last >|");
    //---------Buttons f?r Panel 3-------------------------
    Button neu = new Button("New");
    Button safe = new Button("Safe");
    Button refresh = new Button("Refresh");
    //--------Labels f?r Panel 2-----------------------------
    Label lid = new Label("ID",Label.LEFT);
    Label lname = new Label("Name",Label.LEFT);
    Label lage = new Label("Age",Label.LEFT);
    Label ltel = new Label("Tel.",Label.LEFT);
    Label lmail = new Label("E-Mail",Label.LEFT);
    Label ltext = new Label("Spruch",Label.LEFT);
    Label lub = new Label("Last Button",Label.LEFT);
    TextField id = new TextField();
    TextField name = new TextField();
    TextField age = new TextField();
    TextField tel = new TextField();
    TextField mail = new TextField();
    TextField text = new TextField();
    TextField usedbutton = new TextField();
    //--------ActionEvent bla sachen eben--------------------
    public static void main (String[] args) throws IOException {
    userdata wnd = new userdata();
    wnd.setVisible(true);
    public userdata() throws IOException {                                                                                                                                                                                                                                                                                
    //--------------------------------Layout mit panel bestimmung--------------------------------------
    setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();
    JPanel p3 = new JPanel();
    add(BorderLayout.NORTH ,p1);
    add(BorderLayout.CENTER , p2);
    add(BorderLayout.SOUTH , p3);
    //-------------------------------Funktionslose Buttons in PANEL 1------------------------------------
    p1.add(first);
    p1.add(back);
    p1.add(next);
    p1.add(last);
    p1.add(usedbutton);
    //--------------------------------Funktionierende Textfelder in PANEL 2------------------------------
    Panel labelpanel = new Panel();
    p2.setLayout(new GridLayout(7,3));
    p2.add(lid);
    p2.add(id);
    p2.add(lname);
    p2.add(name);
    p2.add(lage);
    p2.add(age);
    p2.add(ltel);
    p2.add(tel);
    p2.add(lmail);
    p2.add(mail);
    p2.add(ltext);
    p2.add(text);
    p2.add(lub);
    p2.add(usedbutton);
    //--------------------------------------Buttons in PANEL 3-----------------------------------------
    p3.add(neu);
    p3.add(safe);
    p3.add(refresh);
    //--------------------------------BufferedReader -------------------------------------------------
    readData();
    //--------------------------------Panel 2 TextField-----------------------------------------------
    fillForm();
    //================================ActionPerformed==================================================
    first.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("First");
    usedbutton.setText("First");
    back.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Back");
    usedbutton.setText("Back");
    next.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Next");
    usedbutton.setText("Next");
    last.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Last");
    usedbutton.setText("Last");
    neu.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("New entry");
    usedbutton.setText("New");
    safe.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    System.out.println ("Now Saving, do not turn off!");
    usedbutton.setText("Save");
    //-----------------refresh
    refresh.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    try{
    readData();
    }catch( IOException ioe){
    System.out.println("Fehler beim lesen aus Datei");
    fillForm();
    usedbutton.setText("Refresh");
    //=============================================================================Button Funktionen!!!
    pack();
    //--------------------------------WindowsListener hinzuf?gene--------------------------------------
    addWindowListener(
    new WindowAdapter() {
    public void windowClosing(WindowEvent event)
    setVisible(false);
    dispose();
    System.exit(0);
    //-----------------------------------readData() - > Buffered Reader in aktion! --------------------
    private void readData() throws IOException{
    BufferedReader br = new BufferedReader(new FileReader("My .txt File with path"));
    String zeile;
    StringTokenizer st;
    String delim = ";";
    zeile = br.readLine();
    st = new StringTokenizer(zeile, delim);
    st.hasMoreTokens();
    //System.out.println (st.nextToken());
    tokId = new String(st.nextToken());
    tokName = new String (st.nextToken());
    tokAge = new String (st.nextToken());
    tokTel = new String (st.nextToken());
    tokMail = new String (st.nextToken());
    tokText = new String (st.nextToken());
    //--------------------------fillForm() - > f?llt die TextFelder aus!--------------------------------
    private void fillForm(){
    id.setText(tokId);
    name.setText(tokName);
    age.setText(tokAge);
    tel.setText(tokTel);
    mail.setText(tokMail);
    text.setText(tokText);
    }

  • Read files with no app suffixes (.pdf, .doc. xls, etc ...)

    Hi,
    On a Macintosh, files do not have suffixes (.pdf, .xls or .doc, etc ...) to identify the application that created the file. How can I open a file on my iPhone if there is no suffixes ?
    Thanks in advance.

    You're welcome.
    The files on your Mac include the file extension, which you can choose to show or not show with the files on your Mac.
    Since I don't email files to Mac users only, I'm in the habit of including the file extension with all email attachments.
    I'm not aware of a way to force open a file with the iPhone.

  • How to read files with codepage UTF16LE with "Sender File Adapter"

    Hi everybody,
    I am using a XI-Filesender-Adapter to get a (UTF-16LE encoded) file und process it in XI-Mapping.
    This is my File-Content:
    Cost Centre,Cost Code,Page Count (B&W),Page Count (Colour),Job Count
    Unknown,Lexmark,"37,480",334,"11,968"
    Unknown,Unknown,312,0,177
    110000,Lexmark,128,228,43
    The HEX-representation of this content is:
    FF FE 43 00 6F 00 73 00 74 00 20 00 43 00 65 00
    (The starting 2 Bytes FF FE represent UTF16-LE )
    And this is the payload I get for mapping:
    <?xml version="1.0" encoding="utf-8" ?>
    <ns:MT_POM_KOSTEN xmlns:ns="http://aua.com/pom">
    <POM_REC>
      <COSTCENTER>uFEFFCost Centre</COSTCENTER>
      <COSTCODE>Cost Code</COSTCODE>
      <PAGECOUNT_BW>Page Count (B&W)</PAGECOUNT_BW>
      <PAGECOUNT_COL>Page Count (Colour)</PAGECOUNT_COL>
      <JOBCOUNT>Job Count</JOBCOUNT>
      </POM_REC>
    <POM_REC>
      <COSTCENTER>Unknown</COSTCENTER>
      <COSTCODE>Lexmark</COSTCODE>
      <PAGECOUNT_BW>37,480</PAGECOUNT_BW>
      <PAGECOUNT_COL>334</PAGECOUNT_COL>
      <JOBCOUNT>11,968</JOBCOUNT>
      </POM_REC>
    <POM_REC>
      <COSTCENTER>Unknown</COSTCENTER>
      <COSTCODE>Unknown</COSTCODE>
      <PAGECOUNT_BW>312</PAGECOUNT_BW>
      <PAGECOUNT_COL>0</PAGECOUNT_COL>
      <JOBCOUNT>177</JOBCOUNT>
      </POM_REC>
    <POM_REC>
      <COSTCENTER>110000</COSTCENTER>
      <COSTCODE>Lexmark</COSTCODE>
      <PAGECOUNT_BW>128</PAGECOUNT_BW>
      <PAGECOUNT_COL>228</PAGECOUNT_COL>
      <JOBCOUNT>43</JOBCOUNT>
      <POM_REC>
    I can see the correct strings (for example Cost Centre) in  payload, but the string-comparison in the user defines function cannot recognize the equality of the strings:
    for (int i =0; i < a.length; i++) {
    if (
       (a<i>.equals("Cost Centre"))  )
      result.addSuppress();
    else
      result.addValue("");
    Actually I am using UTF-8 as codepage in Fileadapter (and Text as type)
    When I try to use UTF16 (or UTF-16LE) as Codepage, I am getting unreadable characters.
    I also tried binary, UTF16-BE,...
    The only way is to covert the file to ANSI before  I use it with XI. Then my function does work correctly.
    Does anybody have an idea, how I can read a UTF16-LE File and process it correctly in XI?
    I am using XI 7.00 0023  and JSDK 1.4.2-34
    Thanks a lot
    Armin

    Hello Armin,
                        I have gone through some SAP notes and blogs  to find solution to your problem, here is what I found
    1. SAP NOTE 821267
    q) How do I correctly configure the File Encoding used by the File
    Adapter?
    Flat Files with File Content Conversion
    For a File Sender channel, configure the encoding of the source
    file. The file will be interpreted according to the configured
    encoding and converted to XML with an UTF-8 encoding.
    For a File Receiver channel, configure the encoding to match
    the encoding you would like to be written to the target flat
    file.
    - Flat Files without File Content Conversion
    Whether to configure an encoding in this case depends on if you
    want to pass through the file "as is", e.g. within a File
    Sender to File Receiver scenario, or if you want to convert the
    file's encoding on its way through the Integration Server. For
    "as is" processing, configure both the sender and the receiver
    using the File Type setting "Binary".
    To apply an encoding conversion, configure the respective
    source and target encoding in both the sender and receiver
    channel.
    Important: Configuring an encoding in the receiver channel
    will only lead to the expected results if the payload sent to
    the receiver channel is in UTF-8 format (e.g., by having
    specified an encoding conversion in the Sender channel).
    So as per this note if you configure the encoding scheme of sender communication channel to UTF-16LE, adapter should be able to convert it to UTF-8 by default. But you have posted that this encoding scheme is leading to unreadable charcters
    2) SAP note 880173
    This speaks of use of module XMLAnonymizerBean which can be applied to XML payload to change its encoding.
    3) How to guide on encoding : http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42?QuickLink=index&overridelayout=true
    4) SAP note:960663
    http://help.sap.com/saphelp_nw04/helpdata/en/45/da2deb47812e98e10000000a155369/content.htm
    TextCodePageConversion Bean details which might solve your problem.
    5) Finally if nothing above works you need  a java mapping code to convert to target XML structure without any File content conversion. The mapping will convert the received file to proper target XML in "UTF-8" encoding. Please let us know if you need help on the code with this final option.
    Regards
    Anupam

  • Read file with nio and flush with servlet

    Can I read file, by using java.nio (for example by FileInputStream.getChannel()) and then flush the file content thru the servlet?
    I kwow about reading without java.nio, get a byte array and then flush it by httpservletresponse writer or outputstream, but I wish to know if it is possibile with java.nio reading.
    thanks

    I'm doing it only for file reading..
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();    
            FileInputStream fis = null;                               
            try
                String path = "/var/hello.txt";
                fis = new FileInputStream(path);       
                FileChannel channel =  fis.getChannel();
                ByteBuffer bb = ByteBuffer.allocate((int) channel.size());
                channel.read(bb);
                byte[] data2 = bb.array();
                channel.close();
                out.write(new String(data2));
            } catch (FileNotFoundException ex)
                ex.printStackTrace();
            } finally
                try
                    fis.close();
                } catch (IOException ex)
    ex.printStackTrace();
                out.close();
        }

  • Specifying byte stream type for Read File with Type Descriptor

    Hi.
    I'm trying to write a VI that reads an image file format that can have
    different datatypes. What I have so far is that I open the file, read
    the header, and get the width, height, number of frames, and datatype.
    I calculate number of pixels by nrows*ncols*nframes with no problem,
    but I'm not sure how to tell Read File the correct datatype to read
    the data into.
    I tried using a Case structure where I have a Read File in each case
    with the correct type constant as input for that case. The problem is
    that the tunnel graduates the datatype to the highest representation.
    I found in Application Note 154 the discussion about Type Descriptors.
    Is there a way to generate a Type Descriptor and output it from a C
    ase
    structure? I tried just returning the value (e.g. 0x0402 for a Word),
    but Read File will just see that the byte stream type is a uint32.
    Is there any other way to do this?
    Thanks for any help.

    I converted the code to LabVIEW 6.1 for you and attached it below.
    Don't worry about being a newbie. We all start there. Keep asking this type of question and you won't stay there long.
    As you are discovering, being strictly typed means that you must rewrite code even for a simple data type change, or convert everything to the same data type first. For image data, conversion can result in a lot of extra space being wasted. Use a modified version of the GLV_WaveformBuffer.vi to hold your data. Use the array functions, which operate inline, to add to and delete the data wires in the buffer. This allows you to save several different data types. You will need several different inputs and outputs to handle these data types. I ha
    ve also attached a similar file created for exactly the problem you have - storing arrays of different data types (data from NI-SCOPE devices, in this case - can be float, I8, I16, or I32).
    Routines that take any type work in one of two ways. LabVIEW primitives, such as plus and minus operators, work by figuring out the type and doing the right thing in the C code layer of the LabVIEW environment. Users of LabVIEW can't do this. Users can make polymorphic VIs. Polymorphic VIs are actually a single VI for every data type that are referenced by a "wrapper", the polymorphic VI. Users still need to write a different VI for every data type they need.
    Take home message - if you need to work with different data types, you will need to rewrite your code for every data type or convert your data to a common data type. Polymorphic VIs and case statements are your friend.
    Let me know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    GigaLabVIEW61.zip ‏362 KB
    sfpScpChan_Waveform_Buffer.zip ‏74 KB

  • Reading in a file with BufferedReader

    I haven't used Java for anything beyond calculations and simulations so my programming skills aren't great.
    I'm trying to read in a file which contains scientific data. I want to skip two digits, read 5 into one element of an integer array, skip 14 digits, read 5 into another integer array, read another 5 into a third integer array and then skip to the next line. I've worked out that I can use BufferedReader for this and the skip method is easy enough to understand. But the read(Char[],int,int) method has thrown me. It reads my 5 numbers into 5 elements of a character array.
    So how can I get these 5 elements of a character array into one element of an integer array? Or can it not be done? Or is there something similair to BufferedReader that uses int[] instead of char[]?

    Let me repost your data with a monospace font, so that the structure is visible:
    IF13065     382 101215000+10008904031330IIIaF HZ 647 511aU  
    V13066     770   8706360-65008904041005IIaD  GG 495 200a   
    IF13067     382  N1212045+11298904041054IIIaF HZ 6471800a   
    B13068     622  65014200-15008904041429IIaO  GG 385 150a   
    The spaces aren't present in every row of data. It just depends on what astronomical data is needed for that element - (prisms, filters, emulsions etc.)Are the exact positions of the numbers fixed per line? Then do as I suggested:
    Read the whole line and use substring() thats much easier to write and understand than trying to do skip() and read().

  • Why doesn't my text file get read properly with BufferedReader??

    Here is my code:
    File props = new File("c:\\jdk13\\props.spm");
         FileReader in = new FileReader(props);
         BufferedReader br = new BufferedReader(in);
         String line= new String("");
         while(br.readLine() != null){
              line = (br.readLine());
              System.out.println(line);
    I also tried InputStreamReader but that didn't work right either. Basically, I want to read the lines of a text file which looks like this:
    excite.com
    hotmail.com
    yahoo.com
    with the code above, all it sems to read is "hotmail.com" and then a null. what is going on here? anybody have working examples of a BufferedReader reading lines from a text file?
    thanks in advance,
    chuck

    It's happening because you say this:
    read the first line
    put the next line in the variable line
    print it
    read the next line
    put the next line in the variable line
    print it
    read the next line - null so I'm done
    .readln does just what it says - reads the line. That said, you can do this:
    while ( (line = br.readLine() ) != null ) {
        System.out.println( line );
    }

  • Printing Adobe Reader files with a DeskJet 6540 and OS X.6

    Ever since I upgraded to Mac OS X.6, I've had problems printing .pdf files.  No matter what I teil the printer, it only prints one copy of one page of the document.  I've upgraded to Adobe Reader 9.2.0.  Is this a driver problem?  OS X.6 is supposed to take care of that.  Adobe Reader is the only software that causes this problem, and of course Adobe does not provide support.  Any ideas?

    Hi There...I'm having the same problem, although I'm using XP Pro with Service Pack 3 and an OfficeJet 6500 , e709n ...and
    it was working until this past couple of weeks.  I can't print ANY PDF, doesn't matter if it's old or new...  If I "do" a preview, all I see is a line of print across the top of the page.
    Anything else will print other than PDF's, so of course it's driving me nuts! I've even reinstalled the driver for the printer; but it didn't make any difference except for my time and frustration. I hope someone can give us an answer soon...there are important docs I need to print out.

  • How to read file with JNI?

    Hello,
    I want to implement a native function that has as a parameter a File type. For example:
    public native void readFile(File f);
    But as far as I know the JNI does not support File type, or I am wrong? One way to solv this problem i of course to convert the file into an array of chars end then to implement some method like:
    public native void readFile(char [] f);
    So if there is another way of solving this problem, please help me.
    Thank you in advance.:)

    I would recommend against passing a File object as a paramater. The implication of trying to do that is that you will be using the File object, which means you will be making JNI calls back into the JVM in order to do what you need to do. If there are very many of those calls, well, no fun!
    If you do it by hand, then yes, it can be very difficult and time-consuming. Jace, http://jace.reyelts.com/jace, (a free, open-source project) let's you do this sort of stuff in your native code very easily. For example,
    * A C++ function that accepts a java.io.File and reads its contents.
    void readFile( java::io::File& file ) {
      const int bufferSize = 512;
      JArray<JByte> buffer( bufferSize );
      try {
        FileInputStream input( file );
        for ( int numBytesRead = 0; bytesRead != -1; ) {
          numBytesRead = input.read( buffer, 0, bufferSize );
          // Do something with the buffer
      catch ( IOException& ioe ) {
        cout << ioe << endl;
    } is just as easy to write as straight Java, and it's all implemented using standard JNI function calls under the covers. For example, the above code results in the invocation of several JNI functions, like, NewObject, NewByteArray, CallIntMethod, FindClass, GetMethodID, ExceptionOccurred, etc...
    God bless,
    -Toby Reyelts

  • Permission denied when read file with setGID

    I'm using a NFS system. I noticed that once I set setGID to a file, e.g.
    chmod g+s myfileThe file become un-readable (even root user is not able to access it). if I try to read, i got:
    tail myfile
    cannot open `myfile' for reading: Permission deniedWhat could be problem? using ls -l or getfacl, I can see owner,group, other all have read permission though:
    ls -l
    -rw-r-Sr--+  1 oracle dba  5 Sep 19 07:51 myfile
    getfacl myfile
    # file: myfile
    # owner: oracle
    # group: dba
    user::rw-
    group::r--
    mask::rwx
    other::r--

    Using the nosuid option is a good idea and you should consider using this with all NFS mounted disks. It means that the server's root user cannot make a suid-root program on the file system, log in to the client as a normal user and then use the suid-root program to become root on the client too. http://tldp.org/HOWTO/NFS-HOWTO/security.html
    You could ask your system administrator to check file permissions on the parent directory, but it will require a more in-depth review of your configuration to analyze what's going on, and this is not possible unless you provide more information.

  • Read file with size 2Go : Pb

    I'm using a loop with Read Vi to seek in the file. It works well, But When my file is greater than 2 GB, I got a memory error (mémoire insuffisante pour terminer l'opération) when I try to read for example 263000 singles data.
    This error appears when I want to read my 263000 values (not when seeking).
    I don't understand why, because it runs well with a file less than 2 Gb even if I want to read more values.
    Please find attached the example vi. Choose a file and run it : if your file size is less than 2 Gb (but have enough datas (ex : file size 10 Mb), it's ok, but if you run it with a file size more than 2 Gb you have the memory error.
    Help please ...
    Eddy DUCHENE
    12 F Chemin de Boutary
    69300 CALUIRE ET CUIRE
    [email protected]
    Attachments:
    SeekBigFile_tst.vi ‏61 KB

    Hi Eddy,
    There are all kinds of fun issues with files greater than 2 GB. The reason is that files greater than 2 GB can't be directly indexed by using a 32 bit integer (the largest integer type LabVIEW currently has). There are a number of solutions. If you are using an NTFS file system, you should be able to continue reading and writing sequentially as long as you don't wire anything up to the position inputs, however, this usually isn't really practical, since it gives you no random access, and accessing 2 GB of data sequentially is going to be kind of tiring.
    Anyhow, the best solution to your problem would be to use a 64-bit file library. You can install one of these, the HWS library, from most newer versions of the Driver CD which ships with almost all NI products. For a detailed description of the issue and the possible solutions, check out this tutorial:
    http://zone.ni.com/devzone/conceptd.nsf/webmain/6A56C174EABA7BBD86256E58005D9712
    Regards,
    Ryan K.

  • Tomcat 5 under NetBeans 3.6 read files with wrong path

    The problem is quite simple:
    I have XSLT file which I read in my servlet. Under Tomcat 4.1.29 (and earlier till 4.0.1) everything works fine, but Tomcat 5 under NetBeans 3.6 produces an error while he tries to read a file not from a directory
    $CATALINA_HOME/webapps/..
    but from a dir
    $CATALINA_HOME/bin/webapps/...
    anybody knows how to fix it? Why he wants to start reading from "bin" directory
    P.S. Tomcat runs under WIn2000

    Actually, sorry, it's more complicated than that... the rules for <xsl:include> say that by default the transformer will look in the same directory as the XSLT file that's doing this include. But that only works if the transformer knows what directory that is. So if you give the transformer an InputStream containing the XSLT (e.g. by using getResourceAsStream), it has no way of knowing what directory it came from. Use the version that creates a File object for the XSLT, and wrap that in a StreamSource when passing it to the transformer. That works for me.

  • How to read only files with a certain format from folder with java

    I have this folder on the server and I only want to read files from this folder on the server... I only want to read files with the files format starting with error_ and ending with xml... an example of a file would be..
    error_123.xml
    I want something like this
    if(fileName.startsWith("error_") && fileName.endsWith(".xml")){
    but which java package will I have to use to read the file from the directory...

    Create an implementation of the java.io.FilenameFilter interface to match the pattern you need.
    Create a java.io.File object for the folder.
    Use the File.listFiles(FilenameFilter) method to get an array of File objects for the files in the folder that match the pattern.
    For each file in the array, create a FileInputStream, wrap it in an InputStreamReader, and wrap that in a BufferedReader (assuming you want to read the XML files as character streams).

  • How to Write BUFFER & Read TEXT with Encrypt file ?

    I'm using Windows Phone 8.1 RT.
    I have a issue :
    - I write a BUFFER encrypted to file. After, I read file with TEXT. It's throw exception : No mapping for the Unicode character exists in the target multi-byte code page. (//ERROR 2)
    - I write a TEXT encrypted to file. After, I read file with BUFFER. It's throw exception : The supplied user buffer is not valid for the requested operation. (//ERROR 1)
    Code Write Buffer & Read Text.
    //Write Textstring msg = EncryptText.Text;
    //ERROR 1 - Use 1 or 2
    await WriteTextAsync(this.file, msg);
    //ERROR 1
    //Read Buffer
    string msg;
    //ERROR 1 - Use 1 or 2
    IBuffer buffer = await ReadBufferAsync(this.file);
    StreamReader stream = new StreamReader(buffer.AsStream());
    msg = stream.ReadToEnd();
    //ERROR 1
    Code Encrypt-Decypt.
    public static string EncryptString(string msg)
                var bufferMsg = CryptographicBuffer.ConvertStringToBinary(msg, BinaryStringEncoding.Utf8);
                var bufferMsgEncrypted = Encrypt(bufferMsg);
                var msgEncrypted = CryptographicBuffer.EncodeToBase64String(bufferMsgEncrypted);
                return msgEncrypted;
            }public static IAsyncAction WriteTextAsync(IStorageFile file, string msg)
                return FileIO.WriteTextAsync(file, EncryptString(msg));
    public static IBuffer Decrypt(IBuffer bufferMsg)
                var key = CreateKey(KEY);
                var aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
                var symetricKey = aes.CreateSymmetricKey(key);
                var bufferMsgDecrypted = CryptographicEngine.Decrypt(symetricKey, bufferMsg, null);
                return bufferMsgDecrypted;
            }public static IAsyncOperation<IBuffer> ReadBufferAsync(IStorageFile file)
                var buffer = FileIO.ReadBufferAsync(file);
                Task<IBuffer> result = Task.Run<IBuffer>(async () =>
                    var Buffer = await buffer;
                    return Decrypt(Buffer);
                return result.AsAsyncOperation();
    Link demo code :
    https://drive.google.com/file/d/0B_cS3IYO936_akE0cmI4bExJMjh0RU9qR3RvWDBWWElZWC1z/view?usp=sharing

    Please provide a working app so this can be tested. You can upload to OneDrive and share a link here.
    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined
    objects and unknown namespaces.

Maybe you are looking for

  • ICal, iCloud, and meeting invitation woes

    Hi all. Fair warning - I'm brand new to the Mac world. I'm a long-time Windows user who now has a shiny new MacBook Pro, primarily for the benefit of what I can already tell is superior hardware. On the software side, however, I'm struggling with the

  • ITunes 10.1.2.17 and QuickTime 7.69.80.9 will not open in Windows Vista

    When I try to open iTunes, I get the following error message: *iTunes has stopped working* Problem signature: Problem Event Name: BEX Application Name: iTunes.exe Application Version: 10.1.2.17 Application Timestamp: 4d3f51b8 Fault Module Name: Stack

  • MSI 760TF no HDMI to TV

    Can't get HDMI to work from the 760TF to my TV (Samsung) or monitor (LG). DVI works fine! -On my TV I get "No signal". -HDMI cable works fine (from my camera to TV) -Win+P does nothing (nvidia control panel has no HDMI device on list). Don't know wha

  • What is a good defrag utility for OS X?

    Hi, I was wondering what is the recommended defrag utility for 10.4.6. Thanks.

  • Experience with Hyperion DRM to Coherence exports.  options

    Hi All. I am working on a project where Hyperion DRM is feeding Oracle Coherence with the slowly changing structures such as GL accounts, budget accounts, costcenters etc. I am looking to find out if anyone has had experience with this type of projec