Rewrite in text file

Hi all
I used file writer to wirte in text file . then when I close my programe and open it again I want to rewrite in the same text file without deleteing the Previous contents of the file .
How I can do that ?? plz help me

Please read more carefully. You need to use the version that takes two parameters: the name of the file, and whether you wish to keep what's already in the file or clear it.

Similar Messages

  • Read from text file vi won't read file...

    I am very new to LV programming so I hope you forgive any stupid mistakes I am making.   I am using Ver. 8.2 on an XP machine.
    I have a small program that stores small data sets in text files and can update them individually or read and update them all sequentially, sending the data out a USB device.   Currently I am just using two data sets, each in their own small text file.  The delimiter is two commas ",,".
    The program works fine as written when run in the regular programming environment.   I noticed, however, as soon as I built it into a project that the one function where it would read each file sequentially to update both files the read from text file vi would return an empty data set, resulting in blank values being written back into the file.   I read and rewrite the values back to the text file to place the one updated field (price) in it'sproper place.  Each small text file is identified and named with a 4 digit number "ID".   I built it twce, and get the same result.  I also built it into an installer and unfortunately the bug travelled into the installation as well.
    Here is the overall program code in question:
    Here is the reading and parsing subvi:
    If you have any idea at all what could cause this I would really appreciate it!
    Solved!
    Go to Solution.

    Hi Kiauma,
    Dennis beat me to it, but here goes my two cents:
    First of all, it's great to see that you're using error handling - that should make troubleshooting a lot easier.  By any chance, have you observed error 7 when you try to read your files and get an empty data set?  (You've probably seen that error before - it means the file wasn't found)
    If you're seeing that error, the issue probably has something to do with this:
    Relative paths differ in an executable.  This knowledge base document sums it up pretty well. To make matters more confusing, if you ever upgrade to LabVIEW 2009 the whole scheme changes.  Also, because an installer contains the executable, building the installer will always yield the same results.
    Lastly, instead of parsing each set of commas using the "match pattern" function, there's a function called "spreadsheet string to array" (also on the string palette) that does exactly what you're doing, except with one function:
    I hope this is helpful...
    Jim

  • Reading in from a text file

    I'm attempting to write a Combat Converter for a popular online game called Ogame. I'm attempting to read a text file that contians something similiar to the sample of the text file I have provided below. What I want to take out from the file is the first and last time a line that begins with Type and Num that shows up for the attacker and defender. However I'm having trouble figuring out how write it so that it does not take it out for the rest of the lines that start with Type and Num. Do you have any suggestions on how I should go about do so?
    Attacker 1
    Weapons:+10% Shields:+10% Armour:+10%
    Type     S.Cargo     L.Cargo     L.Fighter     H.Fighter     Cruiser     B.Ship     Col. Ship     Recy.     Esp. Probe     Bomber     Dest.     Rip     Battlecr
    Num     1     1     1     1     1     1     1     1     1     1     1     1     1
    Weapon     5     5     55     165     440     1.100     55     1     0     1.100     2.200     220.000     770
    Shields     11     27     11     27     55     220     110     11     0     550     550     55.000     440
    Armour     440     1.320     440     1.100     2.970     6.600     3.300     1.760     110     8.250     12.100     990.000     7.700
    Defender 1
    Weapons:+10% Shields:+10% Armour:+10%
    Type     S.Cargo     L.Cargo     L.Fighter     H.Fighter     Cruiser     B.Ship     Col. Ship     Recy.     Esp. Probe     Bomber     Sol. Sat     Dest.     Rip     Battlecr     Miss.     L.Laser     H.Laser     Gauss     Ion.C     Plasma     S.Dome     LS.Dome
    Num     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
    Weapon     5     5     55     165     440     1.100     55     1     0     1.100     1     2.200     220.000     770     88     110     275     1.210     165     3.300     1     1
    Shields     11     27     11     27     55     220     110     11     0     550     1     550     55.000     440     22     27     110     220     550     330     2.200     11.000
    Armour     440     1.320     440     1.100     2.970     6.600     3.300     1.760     110     8.250     220     12.100     990.000     7.700     220     220     880     3.850     880     11.000     2.200     11.000
    The attacking fleet fires a total of 18 times with the total power of 1.059.543 upon the defender.
    The defender's shields absorb 18.910 damage points.
    The defending fleet fires a total of 33 times with the total power of 1.922.677 upon the attacker.
    The attacker's shields absorb 38.730 damage points.
    Attacker 1
    Type     B.Ship     Col. Ship     Rip
    Num     0     0     1
    Weapon     1.100     55     220.000
    Shields     220     110     55.000
    Armour     6.600     3.300     990.000
    Defender 1
    Type     S.Cargo     L.Cargo     L.Fighter     H.Fighter     Cruiser     B.Ship     Col. Ship     Esp. Probe     Bomber     Dest.     Rip     Battlecr     Miss.     L.Laser     Ion.C     S.Dome     LS.Dome
    Num     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0     0     0
    Weapon     5     5     55     165     440     1.100     55     0     1.100     2.200     220.000     770     88     110     165     1     1
    Shields     11     27     11     27     55     220     110     0     550     550     55.000     440     22     27     550     2.200     11.000
    Armour     440     1.320     440     1.100     2.970     6.600     3.300     110     8.250     12.100     990.000     7.700     220     220     880     2.200     11.000
    The attacking fleet fires a total of 11 times with the total power of 2.276.933 upon the defender.
    The defender's shields absorb 17.510 damage points.
    The defending fleet fires a total of 47 times with the total power of 9.540.458 upon the attacker.
    The attacker's shields absorb 15.761 damage points.
    Attacker 1
    Type     Rip
    Num     0
    Weapon     220.000
    Shields     55.000
    Armour     990.000
    Defender 1
    Type     S.Cargo     B.Ship     Esp. Probe     Bomber     Dest.     Rip     Battlecr     S.Dome     LS.Dome
    Num     0     0     0     0     0     0     0     0     0
    Weapon     5     1.100     0     1.100     2.200     220.000     770     1     1
    Shields     11     220     0     550     550     55.000     440     2.200     11.000
    Armour     440     6.600     110     8.250     12.100     990.000     7.700     2.200     11.000
    The battle ends draw.
    The attacker has lost a total of 10.178.000 units.
    The defender has lost a total of 1.836.800 units.
    At these space coordinates now float 1.776.210 Metal and 1.413.954 Crystal.

    I'm attempting to write a Combat Converter for a
    popular online game called Ogame. I'm attempting to
    read a text file that contians something similiar to
    the sample of the text file I have provided below.
    What I want to take out from the file is the first
    and last time a line that begins with Type and Num
    that shows up for the attacker and defender....Please define "take out from the file". Do you want to read and store just these lines?
    Or do you want to remove these lines from the file and rewrite the file without these lines?
    /Pete

  • Write arrays into a text file in different columns at different times

    Hi,
              I have a problem write data into a text file. I want to write 4 1D arrays into a text file. The problem is that I need to write it at different time and in different column (in other word, not only append the arrays).
    Do you have an idea to solve my problem?
    Thank you

    A file is long a linear string of data (text). In order ro insert columns, you need to rewrite the entire file, because colums are interlaced over the entire lenght of the file.
    So:
    read file into 2D array
    insert columns using array operations
    write resulting 2D array to file again.
    (Only if your colums are guaranteed to be fixed width AND you know the final number of colums, you could write the missing columns as spaces and then overwrite later. Still, it will be painful and inefficient, because column data are not adjacent in the file.)
    LabVIEW Champion . Do more with less code and in less time .

  • Adding And Removing in a text file

    Hi
    I'm trying to make a VI that generates a textfile which saves some data each second and give it some timeframe so that it can maintain only the data that has been generated last 10 seconds or so
    First I have made 2 different files, one is for saving some data each second into a text file, and the other one is for removing the data
    but when i combined those two it doesn't seem to work.
    Could anyone have a look at the file and comment on that?
    thanks
    Attachments:
    test2.vi ‏17 KB
    Time(Sub).vi ‏8 KB

    A couple comments on what you are trying to do. First, doing this with a text file is going to be inherently difficult as you are going to be doing a lot of rewriting of the file. Second, having two VIs (1 to write the data and 1 to remove the old data) is a bad approach - why not design the algorithm so the file is only written to one time for each update cycle? Stop trying to make a poor design work and spend a little time thinking outside the box.
    Hint: think about how you calculate a running average in LV, and what if the indicator out wasn't just an indicator but a file write?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to update a text file?

    I am doing an assignment about a bank account. A text file stores the accounts.
    Account Text file:
    User1|Password1|Balance1
    User2|Password2|Balance2
    When user wants to deposit or withdraw the account, then how can update the balance.
    The problem is the length of balance is not fix. eg. $100 -> $90, vice versa.

    You cannot update a file that way. You're going to have to read the file and rewrite it in another file replacing the old balance value with the new balance value and then overwrite the old file with the new file.
    If the file is not to big you can load the whole file in memory with a String then work on that before rewriting it to the file.
    Otherwise your going to have to read chunks of lines and append them to a temporary file.
    I suppose this is no enteprise application but only a student's assignment, or else you should of course use a database for that kind of job!

  • Text file parsing and output

    Hi,
    I'm extremely new to Java and need to read and parse a text file and generate a new text file with modifications as follows:
    1. Ignore and rewrite comments
    2. Ignore and rewrite compiler commands
    3. (a) Modify function prototypes be removing their return values, if any,
    (b) append an '_VAR' to the function name and args
    (c) add an ampersand to the args when passed by reference
    sample input file:
    /***** comment *****/
    #if (INCLUDE_STATIC_BUILD == OS_FALSE)
    extern OS_MEMORY_POOL *MEM_Non_Cached;
    #endif
    UINT16 TLS_IP_Check (const UINT16 *s, UINT16 len);
    INT32 MEM_Copy_Data(NET_BUFFER buf_ptr, const CHAR HUGE buffer, INT32 numbytes, UINT16 flags);
    sample output file:
    /***** comment *****/
    #if (INCLUDE_STATIC_BUILD == OS_FALSE)
    extern OS_MEMORY_POOL *MEM_Non_Cached;
    #endif
    UINT16_VAR = TLS_IP_Check (&UINT16_VAR, UINT16_VAR);
    INT32_VAR = MEM_Copy_Data(&NET_BUFFER_VAR, name, INT32_VAR, UINT16_VAR);
    I would appreciate any help!
    Thanks.

    Check replies on the other post
    http://forum.java.sun.com/thread.jspa?threadID=680728&tstart=0

  • Text File Database

    Hello,
    i am a student at The Open University "APEIRON" Travnik (www.out.edu.ba), i am pursuing a Masters degree in IT, we have one Exam called Java programming.
    My practical exam part is to create a program that should enable user to manipulate students grades. The app should allow these options:
    - Read students data,
    Read students data, needs to ask a user for students name and some ID (Surname etc.), and after that lists students grades and Courses.
    - Inserting of new grades,
    Inserting of new grades should have option to insert a new Course name, students name and grade for that Course.
    - Change of existing grades.
    Change of existing grades needs to ask for students name and/or ID, surname and the name of a Course and shows his present grade, Then it should have an option to change students grade for that Course.
    For this App all of validations should be done.
    All of the data (students names, Course names, Grades etc.), needs to be stored in text file database?! Now, i am a newb to Java, but i worked before with VB, and SQL, and i saw there are some similarities to acces and modify data in SQL database. But the problem is, i never worked with Flat text file databases and now i am stuck, i do not even know how to create a text database or even to connect Java to that database.
    Please, if anyone can help me i would be very grateful!?

    HaloOo wrote:
    i am pursuing a Masters degree in ITPursuing as in commencing, or pursuing as in first/second year undergraduate student. If the former then I am abit worried at your lack of prior research (or is this how you research).
    Please, if anyone can help me i would be very grateful!?You will need to invest some time in the basics of programming in Java and OOL. There are multiple tutorials available on reading/writing to text files. One thing to note: a text file is treated in the majority of cases like a wipe board. You can write a whole bunch of stuff on it, but if you decide you want to write a line in the middle, then unfortunately you need to read what is currently on the whiteboard, rewrite it, append your new message, then append the remainding text from the white board. IMHO a (RAF) is not applicable in this situation.
    Task1: Java: hello world
    Task2: Introductory tutorials
    Task3: Read a text file/write a text file/display contents of file
    You choose,
    Mel

  • Text Files: Update, Delete, Modify...

    Hello all,
    I know that java.util.Properties class exists to read and write textual information to files. Is there any other tool available to edit and modify information in a text file? Here's the format I am looking for my text file.
    Name=Sri;Occupation=Programmer;FavoriteColor=Green;
    Name=Larry;Occupation=Manager;FavoriteColor=Red;
    Name=Bill;Occupation=Manager;FavoriteColor=Yellow;
    As you can see, there are three records in this text file. I would like to modify one particular value in the record. It seems that I have to rewrite the entire file to do this. Any other solutions?
    Thank you,
    -Sri :)

    Seems to me you have to go through each line. My guess is that you have to modify the particular column based on the value of the other columns? So you have to read them in anyway, then you may use the simple replace( ) method in String to change that value you want to modify.
    PC

  • Ammending Text file

    Is it possible to add or delete new text to a textfile without creating a new file.
    For instance if my text file already has
    a
    b
    c
    d
    and I want to remove 'b' and add 'k', can this be done or do I need to create a new file? If it is possible, how do I specify the line numbers to add or delete?
    Thanks

    i think that you must create a new file.No, you can modify bytes within a file. The problem is when you are trying to change records in a variable record length file.
    For example:
    File contains:
    aaa
    bbbbbbb
    ccccc
    You can not just change record 2 and have the file look like:
    aaa
    zzz
    ccccc
    In this example you would need to either read the file and create a new one as you go or read the file down to the second record and the rewrite the rest of the file.

  • How to zip text files ?

    Hello to everybody,
    My problems is to compress text files into a .zip file, I have used the following method:
    public void zippa() {
    FileReader fileIn;
    BufferedReader in;
    String riga;
    boolean eof = false;
    ZipEntry zEntry;
    try {
    FileOutputStream fout = new FileOutputStream("C:\\Davide\\zip\\W4.zip");
    fileIn = new FileReader("C:\\Davide\\zip\\W4.txt");
    in = new BufferedReader(fileIn);
    riga = in.readLine();
    FileWriter fileOut = null;
    BufferedWriter out = null;
    CheckedOutputStream csum = new CheckedOutputStream(fout, new Adler32());
    ZipOutputStream z = new ZipOutputStream(new BufferedOutputStream(csum));
    zEntry = new ZipEntry("C:\\Davide\\zip\\Sonia.txt");
    z.putNextEntry(new ZipEntry(zEntry));
    fileIn = new FileReader("C:\\Davide\\zip\\W4.txt");
    in = new BufferedReader(fileIn);
    riga = in.readLine();
    System.out.println("Zipping....");
    while (!eof) {
    riga = in.readLine();
         if (riga != null) {
    z.write(riga.getBytes(),0,riga.length());
    } else eof = true;
    System.out.println("Zipped....");
    z.close();
    fileIn.close();
    } catch (IOException ioe) {
    System.out.println("Eccezione: "+ioe);
    ioe.printStackTrace();
    My problem consist in the fact that the different lines which are coming from W4.txt, are not separeted (in the zip entry "Sonia.txt") by a carriage return (new line) character but by an unprintable character (which looks like a square).... I've tried to add a "\n" string to the String variable riga, or to add the following lines:
    z.write((char)13);
    z.write((char)12);
    immediately after the
    z.write(riga.getBytes(),0,riga.length());
    instruction, but these solutions does not work.
    Is someone so kind to help me please ?
    Vacca Davide
    [email protected]

    The readLine() method removes new line characters as it returns one line of data at a time. When creating a zip file you want to retain all the characters in the input file. Below is the code I used to test the creation and reading of a zip file. Hope it helps.
    import java.io.*;
    import java.util.zip.*;
    public class TestZip
    public static void main(String[] args) throws IOException
    zip( args[0] );
    System.exit(0);
    static private void zip(String fileName) throws IOException
              // Write Zip file
    byte[] iobuff = new byte[512];
    int bytes;
    FileInputStream fis = new FileInputStream( fileName );
    ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( fileName + ".ZIP" ) );
    ZipEntry ze = new ZipEntry( fileName );
    zos.putNextEntry( ze );
    while ( (bytes = fis.read( iobuff )) != -1 )
    zos.write( iobuff, 0, bytes );
    fis.close();
    zos.close();
              // Read Zip file and rewrite to verify contents are the same
    ZipInputStream zis = new ZipInputStream( new FileInputStream( fileName + ".ZIP" ) );
    zis.getNextEntry();
    FileOutputStream fos = new FileOutputStream (fileName + ".UNZIP" );
    while ( (bytes = zis.read( iobuff, 0, 512 )) != -1 )
    fos.write( iobuff, 0, bytes );
    fos.close();
    zis.close();

  • JTable - Help with updating a Text File

    Hi all,
    I've been fighting this for a few days. I am trying to update a Text File with my JTable.... Displaying the data works great but when I try to edit a cell/field on the gui, I'm bombing out...... My text fiel is a small user control file with Id, Name,
    Date, etc etc with the fields delimited with a "|".... I have built an Abstract Data Model (see below).... and I think my problem is in the setValueAt method.......
    Thanks so much in advance!!!!
    Mike
    code:
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.io.*;
    import java.util.*;
    public class DataFileTableModel extends AbstractTableModel {
    protected Vector data;
    protected Vector columnNames ;
    protected String datafile;
    public DataFileTableModel(String f){
    datafile = f;
    initVectors();
    public void initVectors() {
    String aLine ;
    data = new Vector();
    columnNames = new Vector();
    try {
    FileInputStream fin = new FileInputStream(datafile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));
    // extract column names
    StringTokenizer st1 =
    new StringTokenizer(br.readLine(), "|");
    while(st1.hasMoreTokens())
    columnNames.addElement(st1.nextToken());
    // extract data
    while ((aLine = br.readLine()) != null) { 
    StringTokenizer st2 =
    new StringTokenizer(aLine, "|");
    while(st2.hasMoreTokens())
    data.addElement(st2.nextToken());
    br.close();
    catch (Exception e) {
    e.printStackTrace();
    public int getRowCount() {
    return data.size() / getColumnCount();
    public int getColumnCount(){
    return columnNames.size();
    public String getColumnName(int columnIndex) {
    String colName = "";
    if (columnIndex <= getColumnCount())
    colName = (String)columnNames.elementAt(columnIndex);
    return colName;
    public Class getColumnClass(int columnIndex){
    return String.class;
    public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;
    public Object getValueAt(int rowIndex, int columnIndex) {
    return (String)data.elementAt( (rowIndex * getColumnCount()) + columnIndex);
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    Vector rowVector=(Vector)data.elementAt(rowIndex);
    rowVector.setElementAt(aValue, columnIndex);
    fireTableCellUpdated(rowIndex,columnIndex);
    // return;
    }

    No, the DefaultDataModel does not update the physical data file. It is just used to store the data as you type in the table cells.
    The code from above is used to read data from a file and populate the DataModel.
    Now you need to write another routine that will take the data from the DataModel and write it to your file. I have never actually done this but I think the code would be something like:
    int rows = table.getModel().getRowCount();
    int columns = table.getModel().getColumnCount();
    //  Write column headers
    for (int j = 0; j < columns; j++)
         TableColumn column = table.getColumnModel().getColumn(j);
            Object o = column.getHeaderValue();
         writeToFile( o.toString() + "|" );
    writeToFile( "\n" );
    // Write each row
    for (int i = 0, i < rows; i++)
        for (int j = 0, j < columns; j++)
            Object o = table.getValueAt(i, j);
            writeToFile( o.toString + "|" );
        writeToFile( "\n" );
    }If you need to update the file whenever data in a cell changes, then you could extend the DefaultTableModel and override the setValueAt() method to also write the contents of the DataModel to a file. But this is a lot of overhead since it rewrite the entire file for every cell change.

  • Sorting of a large text file

    I am rewriting a UNIX script to Java. The UNIX script has syncsort code contained in it. The sort is used to sort large text files. The files consist of very large records, up to 3000 characters. I have the file layouts for the fields within the records. Below are a couple syncsorts showing what I need to re-write.
    The first sort, sorts the file by transaction type and only keeps certain transaction types.
    $SYNCSORT << ____endsort1
    /WARNING 1 /SKIPBLANK
    /INFILE $XJOB/tran.ACHP
    /OUTFILE $XJOB/tran.ACHP.careabout
    /FIELDS tran 1 CHAR 3, seq 4 CHAR 2, check_field 9 CHAR 1
    /CONDITION CARE_ABOUT ((tran="104" OR tran="154" OR tran="165" OR tran="301" OR tran="385") AND (seq="00" OR seq="01")) OR (tran="104" AND check_field !="$")
    /COPY
    /INCLUDE CARE_ABOUT
    /END
    endsort1
    The second sort. sorts by plan number, participant number in ascending order and summarizes the amount. I can summarize the amount after the sort in Java so that does not need to be done in the same sort step.
    $SYNCSORT << ____endsort2
    /WARNING 1 /SKIPBLANK
    /INFILE $XJOB/extract.ACHP
    /FIELDS plan 1 CHAR 6, amount 8 TS 15, partid 23 CHAR 9
    /KEYS plan, partid ASCENDING
    /SUMMARIZE TOTAL amount
    /OUTFILE $XJOB/extract.ACHP.summary
    /END
    endsort2
    What is the best way to read in the file, store the data, i.e. vector or array, and how would I go about sorting a large file with very long records?
    Much thanks in advance!!!

    try looking at the comparable interface and the collections.sort() methods. maybe they will save u a little work. as for using arrays or vectors i would use arraylists/vectors so i could use the collections methods. and for the rest of it, it will depend more on your exact needs and i guess you'll just have to go about and make your own configuration systems etc.. shouldnt be too tuff.

  • Change url text dynamically from text file

    I need to use a text file created from a form to rewrite the
    links on my main page. Can I put some kind of javascript in the
    href so when the page loads it'll rewrite the link to point to
    "newpic1.jpg" where newpic1.jpg is one of the items from the text
    file created by my form?
    Please help, this has got me really stuck. All help greatly
    appreciated!!!
    ff

    flashfloozie wrote:
    > how would I identify what line of the text file each
    link will use?
    >
    > btw I really appreciate you taking time to help me with
    this!!!
    >
    > ff
    that is the difficulty with a text file...
    if the links are to remain only for a session, you can set a
    session var
    a simplified method - using PHP - would be:
    1. form
    <form id="form1" name="form1" method="post"
    action="process_form.php">
    <label for="selectimg">Select Image:</label>
    <select name="selectimg1" id="selectimg">
    <option value="img_blue.gif">Image blue</option>
    <option value="img_red.gif">image red</option>
    </select>
    </form>
    2. process_form.php
    <?php
    $_SESSION['img_array']['img1']=$_POST['selectimg1'];
    ?>
    3. wherever the image needs to be displayed:
    <img src="/images/<?php echo
    $_SESSION['img_array']['img1']; ?>" />
    Please be advised that this is a very simplified version and
    that if you
    do use something like this you have to first clean up
    whatever the form
    submits. NEVER trust user input - it could be malicious
    code...
    Anurag

  • Static method to read text file within JAR.

    I've a small problem. I've got my JAR file stuff working great, so I thought I'd give a go to running it via WebStart. Through a little research, I've found that if you're distributing your application via WebStart, you need to pack up everything in a JAR file. This is no problem for the JDBC drivers, because its already in a JAR, so I should be able to distribute that fine.
    I've managed to digitally sign my application JAR and have a preliminary (i.e. untested) JNLP file set up.
    My problem is, my application gets its available data sources from an external text file. I've already written my own file I/O class which I use in my "commonfiles" package to read in a text file and return it as an array with each element holding a line from the text file. This class is basically just a bunch of static methods.
    So instead of rewriting this, I thought I'd just add a boolean flag to this method to state whether to load this file from the external file system or the JAR file. I've found out that to load a text file from within the JAR you have to use something like: -
    String str = (this.getClass().getResource("/myData.txt")).getFile();
    java.io.File fil = new java.io.File(str);
    java.io.FileReader fr = new java.io.FileReader (fil);
    java.io.BufferedReader bin = new java.io.BufferedReader (fr) ;The sticking point is that my method (ReturnFileAsArray()) is declared as static, because my own FileIO class is just a bunch of static methods to do file I/O stuff. Therefore, I can't use the above method because of the instance variable "this" (I assume).
    Is there any way I can load an included text file as above without having to declare my method as an instance method? I guess I could write a seperate class to do this for my commonfiles package, but I'd rather not if possible.
    Any ideas?

    Don't put a "flag" and code different ways to read files depending on whether it's in a JAR or not. Just use
    the getResource/getResourceAsStream API regardless. Hmmm.....so that will load it from either place depending on the situation? I keep getting a NullPointerException doing that, on this line: -
    String strFileName = (FileIO.class.getResource(fileName)).getFile();...although I've only tried it using the external local filesystem file (in the same directory) as I've not really finished setting up my WebStart stuff yet.
    Here is the method in question...
    public static String[] ReadFileAsArray(String dirName, String fileName, boolean bFromJAR) {
            String[] resultStringArray = null;
            StringBuffer strBuffer = null;
            StringTokenizer strTokenizer = null;
            FileReader fReader = null;
            BufferedReader bReader = null;
            int iElementCount = 0;
            if ((dirName.length() < 1) || (fileName.length() < 1)) {
                // Null parameters found. Failure.
                return null;
            } else {
                // Parameters correct, continue.
                try {
                    // Read the file contents and convert to String array.
                    //if (bFromJAR) {
                        // Open file from within JAR file.
                        String strFileName = (FileIO.class.getResource(fileName)).getFile();
                        File jarFile = new File(strFileName);
                        fReader = new FileReader(jarFile);
                    //} else {
                        // Open from local filesystem.
                    //    fReader = new FileReader(dirName + File.separator + fileName);
                    bReader = new BufferedReader(fReader);
                    strBuffer = new StringBuffer();
                    while (bReader.ready()) {
                        strBuffer.append(bReader.readLine() + "%%");
                    strTokenizer = new StringTokenizer(strBuffer.toString(), "%%");
                    resultStringArray = new String[strTokenizer.countTokens()];
                    while ((strTokenizer.hasMoreTokens()) && (iElementCount < resultStringArray.length)) {
                        resultStringArray[iElementCount++] = strTokenizer.nextToken();
                    bReader.close();
                    return resultStringArray;
                } catch (IOException e) {
                    return null;
        }I'm calling it using: -
    // Load the external file into a String array, one row for each element.
    String[] fileArray = FileIO.ReadFileAsArray(System.getProperty("user.dir"), "datasources.dat", true);Cheers on any info on this.

Maybe you are looking for