Bufferedreader class

hi,
im trying to use a buffered reader class to import data from a txt file and assign the data values to different data types within the application.
however, i sometimes have the trouble that the reader gives me a null value from the reading of the first line, instead of returning what is actually there...
the text file looks something like this
Joe Bloggs //To be assigned to Name string within app
123 Acre Wood //Assigned to Address 1 String within app..
Bloggsville //Assigned to address 2 string within app
however when i use the bufferedreader it gives me a null for reading the first line...
This doesnt always happen and ive tried cleaning up and building the main project within netBeans several times to flush out bad code.
i've been told that a null value means it has reached the end of the file, but how can it have done if it is the first line to be read?
is there any way of ensuring that the first line read by the file is definately the first line of the text?
thanks
richard.

Are you sure you're actually getting a null and not, say, a zero-length String?
I've never seen this problem before and BufferedReader is so commonly used that it's hard for me to believe that such a bug exists.
Have you written a tiny sample program that demonstrates this behavior? If so, please post it (using [code] tags).

Similar Messages

  • Issue with close() method of BufferedReader class and FileInputStream class

    I have written the following code to a text file, called hello,txt from Windows. Everything works fine but I am trying to figure out whether calling of close() method of aforemetioned class is appropriate or necessary thing to do.
    Here are the questions:
    1. Is it necessary to call close method in this senario? And why? [it seems to me that everything gets cleaned up automatically anyways at the end of each call to the method when called from main()]
    2. If the answer for No.1 is yes, then in which order each close method should be called? Or, does the order of calling close method matter anyways?
    3. Is the reason for why in No.1 is that because calling close method on each object is a necessary step to do when dealing with mutli-thread?
    Thanks for your help in advance!
          * Below is an example to clarify my questions
         void readWinFile() {
              File objFile = new File("hello.txt");
              FileInputStream fileStream = null;
              BufferedReader bfReader = null;
              try {
                   fileStream = new FileInputStream(objFile);
                   bfReader = new BufferedReader(
                                      new InputStreamReader(fileStream, "MS932"));
                   int tmp;
                   while ((tmp = bfReader.read()) != -1) {
                        System.out.print((char)tmpLine);
              } catch (FileNotFoundException e) {
                   System.err.printf("File: %s Not Found @ DIR = %s",
                                       objFile.getName(), objFile.getParent());
              } catch (UnsupportedEncodingException e) {
                   System.err.printf("Internal failure: %s", e);
              } catch (IOException e) {
                   System.err.printf("File: %s close failure", objFile.getName());
    *          } finally {*
    *               if (bfReader != null) {*
    *                    try {*
    *                         bfReader.close();*
    *                    } catch (IOException e) {*
    *                         e.printStackTrace();*
    *               if (fileStream != null) {*
    *                    try {*
    *                         fileStream.close();*
    *                    } catch (IOException e) {*
    *                         e.printStackTrace();*
    }Edited by: Jay-K on Feb 14, 2010 8:50 PM
    Edited by: Jay-K on Feb 14, 2010 8:52 PM

    Hello CeciNEstPasUnProgrammeur,
    Thank you for taking your time and doing all these write-up for me.
    CeciNEstPasUnProgrammeur wrote:
    Pretty much every native resource, most notably DB connections because those even remain open after the client process terminates. But ports or file handlers are similar; note that a JVM does not necessarily terminate just because you close your program in "extreme cases" (shared use of JVM). In an app server this is certainly never the way. And even if it does, as long as your app is running, the stuff is certainly never released.What you meant is that if my app runs on an app server, which shared the use of JVM with multiple apps, without properly closing ports or file handlers could cause JVM to keep retaining the native resource allocated for my app. In case of that, the resource leaks would occur.
    On the other hand, if my app runs on an app server, which do not share the use of JVM, the leaks would be less likely to happen even if the ports or file handlers are not manually closed. (It could be a very poor design but technically I could reply on their finalizers to clean up the mess)
    >
    Another misconception seems to be that objects are automatically GCed the moment they run out of scope. This is not true.Is there any documentation somewhere that you could refer me to? I would like to figure out why objects are not auto-GCed when they run out of their scope.
    >
    And lastly, objects should not rely on their finalizers to release native resources, and should rather provide close/release methods. This is a common paradigm, and that's also why releasing the file handle won't work by simply letting the reader instance run out of scope. Nobody notifies the underlying OS.I see, so the JVM here interacts with the underlying OS to acquire sufficient native resource for its apps to run. Without explicit closing, which would make JVM not to notify underlying OS to release acquired resource. Am I on the ball here?
    Thanks,
    Jay

  • Mark() method in BufferedReader class

    any body can help. How to use mark() method in BuffredReader class please give code sample

    You should first read the api - javadocs
    mark
    public void mark(int readAheadLimit)
    throws IOExceptionMark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.
    Overrides:
    mark in class Reader
    Parameters:
    readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail. A limit value larger than the size of the input buffer will cause a new buffer to be allocated whose size is no smaller than limit. Therefore large values should be used with care.
    ram.

  • How to disply empty cell from a string using stringtokenizer class

    Hello All
    I had wriiten a small program to read the string and split the string into different tuples.When i had empty cell in string i am unable to display it. Can any body help me out pls?
    code given below
    import java.io.*;
    import java.util.StringTokenizer;
    class Tokenize {
    // Create BufferedReader class instance
    static InputStreamReader input = new InputStreamReader(System.in);
    static BufferedReader keyboardInput = new BufferedReader(input);
    static String record;
    /* Main method */
    public static void main(String[] args) throws IOException {
         //declare the string variables
         String text,delim,var,delimv,vname;
         String X = "x";
         int i = 1;
         //read the inputs from keyboard for variables and delimv
         System.out.print("What is your variable names? ");
    var = keyboardInput.readLine();
    System.out.println("variable are :" + var );
         System.out.print("What is your separator? ");
         delimv = keyboardInput.readLine();
         //read the inputs from keyboard for string and delim
    System.out.print("What is your String? ");
    text = keyboardInput.readLine();
    System.out.println("String is :" + text );
         System.out.print("What is your separator? ");
         delim = keyboardInput.readLine();
         //create the stringtokenizer class instance
         StringTokenizer vt = new StringTokenizer(var,delimv);
         StringTokenizer st = new StringTokenizer(text,delim);
         //print the nexttokens as long as tokens and variables are available
         while (vt.hasMoreTokens()) {
         while (st.hasMoreTokens()) {
         vname = vt.nextToken();
         //     if(st.nextElement() == X){
         // System.out.println("filed is empty");
         // System.out.println(vname + "= ");
         System.out.println(vname + "=" + st.nextToken());
                   //nextToken());
    Variables name : cat1,cat2,cat3,cat4,cat5,cat6,cat7,cat8,cat9,cat10,cat11
    String name : Produkten;Voor hem;;Funny Mask ;12.50;4.90;17.40;1-5 dagen;0;http://www.eroticastore.nl/ProductDetails.asp?ProductId=21733&ReferrerId=134;http://www.eroticastore.nl/ProductImages/thumb_3300000510.jpg
    Note : Empty cell is in between "Voor hem" and "Funny Mask"
    Thanks In advance,
    Murali

    When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read.

  • BufferedReader cannot resolve symbol

    Hi,
    I need some help with a java program which reads xml files to a specified location, running it on a UNIX machine using Java 1.4.1. I modified the code to include the BufferedReader class, but it keeps complaining about not being able to resolve symbol at line 50 & 53. Any help here would be appreciated, since I'm a newbie.
    bash-2.05$ javac outputScript.java
    outputScript.java:50: cannot resolve symbol
    symbol : constructor InputStreamReader (java.lang.String)
    location: class java.io.InputStreamReader
    BufferedReader in = new BufferedReader(new InputStreamReader("in"));
    ^
    outputScript.java:53: cannot resolve symbol
    symbol : method available ()
    location: class java.io.BufferedReader
    while (in.available() !=0)
    Here's the code:
    //package cognos8_3;
    import java.io.*;
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.File;
    * outputScript.java
    * Copyright Cognos Incorporated. All Rights Reserved.
    * Cognos and the Cognos logo are trademarks of Cognos Incorporated.
    * Description: (KB 1013700) - Sample script that will rename output files generated by CM.OUTPUTLOCATION - Cognos 8.3
    class outputScript
    public static void main(String args[])
         String reportName = "";
         String reportViewName = "";
         String outputLocation = "/data/cognos/rn_filecp/";
         String defName = "";
         String ofTime = "";
         String burstKey = "";
         int countRenamed = 0;
         // get the list of desc files in the outputlocation
         File descFiles = new File(outputLocation);
         String[] children = descFiles.list();
         if (children == null || children.length == 0)
              System.out.println("Invalid file location or no reports found to rename.");
         else
                   System.out.println("Found " + children.length + " files in this location, search for file names containing '_desc.'.");
              for (int i=0; i<children.length; i++)
                   try
                        // Get filename of file or directory
                        String filename = children;
                        if (filename.indexOf("_desc.")>=0)
                             // Open the file that is the first
                             // command line parameter
                             FileInputStream fstream = new FileInputStream(outputLocation+filename);
                             FileInputStream bis = new FileInputStream(fstream);
                                  BufferedReader in = new BufferedReader(new InputStreamReader("bis.in"));
                             //      Continue to read lines while there are still some left to read
                             while (in.available() !=0)
                                  String temp = in.readLine();
                                  System.out.println(temp);
                                  // check for report name
                                  if (temp.indexOf("report[@name=")>0)
                                       // get beginning of name
                                       int startIndex = temp.indexOf("report[@name=&apos;");
                                       String startString;
                                       int endIndex = 0;
                                       if (startIndex > 0)
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("&apos;") + 5; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("&apos;");
                                       else
                                            startIndex = temp.indexOf("report[@name=");
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("@name=") + 6; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("]");
                                       // get report name
                                       reportName = startString.substring(startIndex+1, endIndex);
                                       //System.out.println("Found report name - " + reportName);
                                  else if (temp.indexOf("reportView[@name=")>0)
                                       // get beginning of name
                                       int startIndex = temp.indexOf("reportView[@name=&apos;");
                                       String startString;
                                       int endIndex = 0;
                                       if (startIndex > 0)
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("&apos;") + 5; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("&apos;");
                                       else
                                            startIndex = temp.indexOf("reportView[@name=");
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("@name=") + 6; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("]");
                                       // get report name
                                       reportViewName = startString.substring(startIndex+1, endIndex);
                                       //System.out.println("Found reportView name - " + reportViewName);
                                  else if (temp.indexOf("</fileName>")>0) //check for default name
                                       defName = temp.substring(temp.indexOf(">")+1, temp.lastIndexOf("<"));
                                  else if (temp.indexOf("asOfTime")>=0) // get the time to assure uniqueness when saving
                                       ofTime = temp.substring(temp.indexOf(">")+1, temp.lastIndexOf("<"));
                                       // clean colons from time
                                       ofTime = ofTime.replaceAll(":","_");
                                  else if (temp.indexOf("</burstKey>")>=0)
                                       burstKey = temp.substring(temp.indexOf(">")+1, temp.lastIndexOf("<"));
                             in.close();
                             if (reportName.length() == 0)
                                  reportName = reportViewName;
                                  //System.out.println("Renaming using view name - no report name found");
                                       String format = defName.substring(defName.length()-3, defName.length());
                             // new description xml file
                                       File file = new File(outputLocation+filename);
                             File newDescFile = new File(outputLocation + reportName+"_"+burstKey+"_"+ofTime+"DESC_" + format+ ".xml");
                                       // new renamed specific format file.
                             File file3 = new File(outputLocation+defName);
                             File newDefFile = new File(outputLocation + reportName+"_"+burstKey+"_"+ofTime+"."+format);
                             boolean success = file3.renameTo(newDefFile);
                             if (!success)
                                  // File was not successfully renamed
                                  System.out.println("ERROR attempting to rename - " + file3.getAbsolutePath() + " to \n\t\t" +
                                            newDefFile.getAbsolutePath());
                             else
                                  countRenamed++;
                                  // File was successfully renamed
                                  System.out.println(countRenamed +") Renamed - " + file3.getAbsolutePath() + " to \n\t\t" +
                                            newDefFile.getAbsolutePath());
                             // Rename file (or directory)
                             success = file.renameTo(newDescFile);
                             if (!success)
                                  // File was not successfully renamed
                                  System.out.println("ERROR attempting to rename - " + file.getAbsolutePath() + " to \n\t\t" +
                                            newDescFile.getAbsolutePath());
                             else
                                  // File was successfully renamed
                                  System.out.println(" - " + file.getAbsolutePath() + " to \n\t\t" +
                                            newDescFile.getAbsolutePath());
                   catch (Exception e)
                        System.err.println("File input error " + e.getMessage()) ;
         System.out.println("Complete.");
    Thanks,
    Nick
    Edited by: nickmills on Aug 31, 2008 5:05 PM

    First, you only need to create the FileInputStream once. Then that's what you pass to the InputStreamReader constructor. Your code for reading from the BufferedReader is also wrong.FileInputStream fstream = new FileInputStream(outputLocation+filename);
    // FileInputStream bis = new FileInputStream(fstream);  <-- remove this line
    BufferedReader in = new BufferedReader(new InputStreamReader(fstream));
    // available() doesn't do what you think it does; forget about it.
    // Here's the standard way to use a BufferedReader
    String line = null;
    while ((line = in.readLine()) != null)
      // process 'line'
    } There are probably other errors in the code, but reading all that unformatted code is too much of a hassle. In future, please use &#x7B;code} tags when posting source code.

  • Class not found !  HELP !

    Dear Java People,
    Hello how are you today ?
    I have an error in my Support System class that says
    "class InputReader not found" in the following lines of code:
    private InputReader reader;
    and also this error is found in the below line of code:
    reader = new InputReader();
    below is the class where the error originates
    and the other classes also
    thank you in advance
    Stan
    /*This class uses an object of class InputReader to read input
    from the user at the keyboard,  and an object of class Responder
    to generate responses. */
    import java.io.BufferedReader.*;
    import java.io.InputStreamReader.*;
    public class SupportSystem
      private InputReader reader;
      private Responder responder;
      /* create the input and output objects of a technical support system */
      public SupportSystem()
        reader = new InputReader();
        responder = new Responder();
      /* Start the technical support system
          this will print a welcome message,
          enter into a dialog with the user
          until the user ends the dialog with "bye" */
      public void start()
        boolean finished = false;
        printWelcome();
        while(!finished)
          String input = reader.getInput();
          if(input.startsWith("bye") )
            finished = true;
          else
            String response = responder.generateResponse();
            System.out.println(response);
        printGoodbye();
    //print a welcome message
      private void printWelcome()
        System.out.println("Welcome to the technical support system");
         System.out.println();
         System.out.println("We will assist you with any problem you might have");
         System.out.println("Please type \"bye\" to exit our system");
      //print a goodbye message to the screen
      private void printGoodbye()
        System.out.println("Nice talking to you. Bye....");
    ======================================================================
    import java.io.BufferedReader.*;
    import java.io.InputStreamReader.*;
    /* this class reads text input from the keyboard */
    public class inputReader
       private BufferedReader reader;
       /*creates a new input reader to read text from the keyboard*/
           public InputReader()
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
           /* Read a line of text from the keyboard and return it
             as a set of words
           @return   a set of words. each String is a word typed in */
           public String getInput()
             System.out.print("> ");
             String inputLine = readInputLine();
             return inputLine;
           /* read one line of input and return it as a String */
           private String readInputLine()
             String line = "";
             try
             {  //method is from BufferedReader class
               line = reader.readLine();
            catch(java.io.IOException e)
              System.out.println("Error during reading " + e.getMessage());
            return line;
    =====================================================================
    public class Responder
       /*Constructs a responder */
       public Responder()
       /*Generate a response
       @return  A String that should be displayed as the response */
       public String generateResponse()
         return "That sounds interesting ...Tell me more...";
    =====================================================================
    import java.io.BufferedReader.*;
    import java.io.InputStreamReader.*;
    public class TrySupportSystem
        public static void main(String[] args)
          SupportSystem mySupportSystem = new SupportSystem();
         mySupportSystem.start();

    i looked at the code quickly but noticed that you declare you class as:
    public class inputReader
    but used:
    private InputReader reader;
    java is case sensitive so I (uppercase) is different from i (lowercase).

  • How to skip the '\n' char when reading with BufferedReader

    Hello to all the comunity that is at these forums, ;)
    I'm a venezuelan IT student, and as many arround here, I'm looking for some help with this homework...
    well the thing is that I need to read from the System.in untill I get the "" String. Well the initial idea was to make a BufferedReader object and put the br.readLine(); method inside a recursive method, like this:
       import java.io.*;
        public class P1_diccionary {
          String[] diccionario;
          int cont=0;
           void llenarDiccionario(String linea, String[] auxi)throws IOException{
             if(linea.compareTo("")!=0){
                 int aux = cont++;
                 diccionario = new String[cont];
                 for(int i=0;i<auxi.length;i++)
                     diccionario=auxi[i];
    diccionario[aux]=linea;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    llenarDiccionario(reader.readLine(),diccionario);
    well, I think this one it's a nice idea, however, it doesn't work for me because the input is going to be just like this:
    word1: concept1...
    word2: concept2...
    word3: concept3...
    word4: concept4...
    and! it's going to be pasted on the console (that is "ctrl+c" then "ctrl+v")... that's the real problem that I have, the method that I did reads some lines not all of them, I think it's because there is no synchronization (guessing) between the ctrl+v and the execution of the program...
    so I thought about skiping the '\n' char, to do this I checked the readLine() method of the BufferedReader and found out that it calls a
    readLine(boolean ignoreLF)method and that ignoreLF and skipLF -boolean form the class- determine whether readLine() will skip the '\n' char or not:
    boolean omitLF = ignoreLF || skipLF;ok now the question: how do I make ignoreLF or skipLF = true? I tried to look more in the BufferedReader class but I didn't see how to change the skipLF value...
    well guess that's all, I'll really apriciate all of your help, and any other ideas that you might have to solve the problem...
    well thanks to everybody and see ya ;)

    Use read() instead of readLine(). This method will read characters, and does not treat the EOL charactger the same way. Just keep reading until you find a sequence of characters (two EOL sequences in a row) that matches your end condition. Just be careful, since different OSs have different EOL sequences ... \n, \n\r, or \r. Also, remember that you will have to deal with the EOL sequences. They will not be discarded automatically.
    You can also use read( char[], int, int) to read as many characters as you want, without regard to EOL sequences. This will only stop reading when EOF is reached, or when the next read will cause the underlying stream to block, or when you have read a specified number of characters. Again, this will not terminate at a EOL sequence, and will include the EOL sequences in your array.
    As far as readLine() is concerned, I think you want to stop when you have TWO successive reads that equal "".
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • No BufferedReader Problem!

    I am developing a MIDP application, there is no BufferedReader class to read the file Input. Any other method to cope with it? thanks

    If you are dealing with just ASCII characters, a BufferedInputStream will work.import java.io.*;
    class BuffReader {
         public static void main(String[] args) throws IOException {
              File f = new File("afile.txt");
              BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
              byte[] b = new byte[(int)f.length()];
              in.read(b,0,b.length);
              in.close();
              //construct a String from the byte array:
              String s = new String(b);
              System.out.println(s);
    }Otherwise, you can have a look at source in java.io.* (Reader.java, InputStreamReader.java, BufferedReader.java).
    Cheers!

  • BufferedReader confusion ?

    why everytime InputStreamReader is used with BufferedReader class to take input from key board ?
    why it is so confusing to take just one input in java ?

    LazarusLong wrote:
    +"why it is so confusing to take just one input in java ?"+
    I'm by no means an expert but I think it's not necessarily a question of confusing as it is complexity. Input may not be as simple an issue as you imagine. Bear in mind that a Java program is not restricted to receive that input from a standard PC keyboard. That input may come from a keyboard on a coffee machine or a hand-held device such as a PDA or a cell phone.I hope that people don't program the behavior of coffee machines in java!
    what happened to good old assembly language?

  • BufferedReader default-size

    For construct BufferedReader(Reader in)
    in class java.io.BufferedReader
    Its interpretation is:
    'Create a buffering character-input stream that uses a default-sized input buffer'.
    How can I get the default-size of the BufferedReader instance created by such construct?
    Thanks in advance!

    Look at the source code for the BufferedReader class. You should have a src.zip file in the root directory where you installed the JDK. Unzip it and take a look.

  • Form feed, null and StringTokenizer

    is form feed recognized as null when using the StringTokenizer?
    i currently have my StringTokenizer set with a blank space and i am attempting to read until the value is (EOF) null and while it hasMoreTokens. the text file that i am reading from spans across several pages. my code falls out of my loop when it hits the last space on my first page.

    a form feed (\f) is not a null but that shouldn't be stopping the StringTokenizer, I suspect that the manner in which you're reading in the data may be the culprit. Try to use the BufferedReader class to read your file.
    V.V.

  • New Line in Text File

    Hi -
    Im using the FileWriter and BufferedWriter classes to output text into a .txt file.
    The text I am writing is taken from another text file using the FileReader and BufferedReader classes.
    The text is reading from the file, and will also output to the new text file, however it won't insert a new line, it only inserts an 'unprintable' character i.e. an empty square
    My code is below - its only starting out so its farily simple at the moment, just reading from one file and outputting to another.
    Is there a way i can get the actual new line/carriage return inserted instead of the empty square. (im running Windows XP)
    Thanks in advance
    import java.io.*;
    public class Pad {
    private String inputPath;
    private String outputPath;
    /** Creates a new instance of Pad */
    public Pad() {
    inputPath = "C:\\OUTBOUND.TXT";
    outputPath = "C:\\04'06.txt";
    * @param args the command line arguments
    public static void main(String[] args) {
    // TODO code application logic here
    System.out.println("PAD File");
    //Read PAD File
    Pad p = new Pad();
    p.readPADFile(p.inputPath, p.outputPath);
    public void readPADFile(String inputPath, String outputPath)
    inputPath = this.inputPath;
    outputPath = this.outputPath;
    //System.out.println(inputPath);
    int recordCount = 0;
    String record = null;
    try
    FileReader fr = new FileReader(inputPath);
    FileWriter fw = new FileWriter(outputPath);
    BufferedReader br = new BufferedReader(fr);
    BufferedWriter bw = new BufferedWriter(fw);
    record = new String();
    while((record = br.readLine())!=null)
    recordCount++;
    //System.out.println(recordCount + ": " + record);
    bw.write(record + "\n");
    bw.close();
    br.close();
    fw.close();
    fr.close();
    }catch(IOException e)
    System.out.println("IOException Error");
    e.printStackTrace();
    System.out.println(e.toString());
    }

    I assume by using the
    System.getProperty("line.separator") that this will
    work independent of platform.Yes. And using bw.println() instead of bw.print() will already do it for you. So all you need to change in your program are two letters.

  • How to read file at server? URGENT

    hi,
    I got stucked to read a file which is at the server, i used this code :
    java.io.FileInputStream fis;
    String ipaddr="";
    int ch;
    try
         fis=new java.io.FileInputStream("server.ini");
         while((ch=fis.read())!=-1)
              ipaddr=ipaddr+(char)ch;
         ipaddr=ipaddr.trim();
         System.out.println(ipaddr);
    }catch(Exception e){System.out.println(e);}
    I'm getting a FileNotFound exception, where i went wrong.

    Hello hikiran.
    The server.ini file should reside in your application working directory. If it's not there, then the JVM won't find it. Otherwise you could specify an absolute path to the file, but your application will be less portable. Another choice you have is to define an environment variable which tells your app where the server.ini file resides, with the command
      java -Dmyapp.ServerIni=C\SomeFolder\server.ini myappThen you retrieve the pathname with:
       String path = System.getProperty("myapp.ServerIni");This way your app does not depend on the filesystem on which it's been installed to, because changing the command line that starts your app will be enough to have it working.
    Note: if you have to read a text file consider using the java.io.BufferedReader class which lets you to get rid of the different text file formats problems you find when you move to a unix like platform (newline characters are different).

  • Open an xml file from a URL

    i am trying to open an xml file from a URL.
    i have been using the standard (i think!) xml suite, part of the System Events. is this possible? is this the best way? are there alternatives? any good tutorials of how to use it too?
    the file i am trying to open is: http://www.tvrage.com/feeds/episode_list.php?sid=xxxx
    where "xxxx" is a number of a show, e.g. 2930 is buffy
    regards
    jingo_man

    It works!!
    I used the URL and BufferedReader classes to fill the parser. Here's how:
    // create a new object of type URL
    URL xmlURL = new URL( "http://ServerName/DbName/PageName?OpenPage&username=myname&password=mypassword");
    // Create the SAX2 parser
    SAXParser saxParser = spf.newSAXParser();
    xr = saxParser.getXMLReader();
    // Set the ContentHandler
    DefHandlerClass myHandler = new DefHandlerClass();
    xr.setContentHandler( myHandler );
    // read the URL stream into the BufferedReader
    BufferedReader in = new BufferedReader( new InputStreamReader(xmlURL.openStream()));
    // parse the document
    xr.parse( new InputSource( in ) );
    // close the input stream
    in.close();
    PjR

  • Plz help me out I am a newbie

    import java.io.DataInputStream;
    class CalculateAccnDist
         public static void main(String args[])
    DataInputStream in = new DataInputStream(System.in);
    float a=0.0f;
    float u=0.0f;
    try
                        System.out.println("Enter the initial speed in m/sec :");
                        u = Float.valueOf(in.readLine()).floatValue();
                        System.out.println("Enter the acceleration of the body :");
                        a =Float.valueOf(in.readLine()).floatValue();
                   catch (Exception e) { }
                   System.out.println(" Time(s) Distance(m)");
                   for(int t=0;t<=60;t=t+10)
                             System.out.println(t + ((u*t) + ((a*t*t)/2)));
    I am having two warnings, the warnings are :
    Note: D:\j2sdk1.4.2_11\bin\CalculateAccnDist.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.
    whan I compile with -deprecation , I found the compiler is giving warning in the reading from keyboard statemant i.e. :
    u = Float.valueOf(in.readLine()).floatValue();
    a =Float.valueOf(in.readLine()).floatValue();
    the error is pointed out at ==> in.readLine
    for this warning i am also not able to run the program.
    Plz help me out, I am a newbie in java.
    Thank You
    Tirthankar

    From the API....
    readLine()
    Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:
    DataInputStream d = new DataInputStream(in);
    with:
    BufferedReader d
    = new BufferedReader(new InputStreamReader(in));
    USE BufferedReader INSTEAD OF DataInputStream

Maybe you are looking for

  • Airport / Wii no longer friends

    Hi - I have a Mac Mini, running 10.3.9, connected to a wired router. For nearly a year I've been using the built-in Airport card to share out my broadband connection to my Nintendo Wii, and for most of that time the setup has worked perfectly. A coup

  • Delete page in a section?

    If a section covers several pages in Word process, I haven´t been able to individualize the page in order to delete it. ¨Delete Pages¨ forces me to delete the entire section. If I erase the text and the drawings in the page using the ¨Delete¨ key, th

  • How Can i Use /db2/ DBSID /saptemp* tablespace in DB2 9.5

    Hi Guys, I have installed a new system DB2 and at the time of installation i defined 1 mount point as /db2/SID/saptemp1 but it is not being used. I have two queries ? 1. How can i use /db2/SID/saptemp1 tablespace in DB2 at the time of installation ?

  • RMAN-06172 error when restoring to a DR system

    Hello, I am not a trained DBA, I only have some basic understandings and what I can figure out from the manuals and googling. I have a production 10G R2 database, on Red Hat 5, that I backup using Backup Exec 2010. I perform weekly live Full backups

  • Query builder 10g

    Hi Friends, I want to teach end users make their own reports using QUERY BUILDER 10g. Where do I download this software? Is this stand alone? Thanks a lot