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.

Similar Messages

  • Help with inputting from text file.

    Okay, been struggling with this for a couple days and I could really use some help.
    I need to input text one line at a time into String[] text, I'm reading from a file called "textfile.txt" and I want to store the result
    String[] text = { first_line, second_line, third_line, fourth_line...........etc}
    This works now:
    //code
    String[] test =
         { "1 2, 3 4, 5 6"
         for (int i = 0; i < test.length; i++) {
         Graph g = new Graph(test);
    // end code
    But that of course reads "1 2, 3 4, 5 6" from the code, and not from a text file. My StringTokenizer looks for a "," and makes that the end of the token, so I need to add a "," after each line as well.
    In other words, I need to turn the text file :
    "1 2
    3 4
    5 6"
    into :
    "1 2, 3 4, 5 6"
    These are just numbers to test of course, the real text file I need to input has hundreds of lines.
    Any help would be appreciated, thank you.

    I'm fairly lost. I understand that you need to read a file, and that file contains many lines which each contain a pair of numbers. But then you say (a) that you need to create an array of Strings and (b) that you need to store the result. And there's this mysterious StringTokenizer in there as well. You seem to be suggesting some solution that concatenates all the lines together, with commas between them, so that the StringTokenizer can then go through that concatenation and break it apart into the original pieces.
    Okay, here's some code that reads through a file and makes an array of Strings, one entry per line:BufferedReader in = new BufferedReader(new FileReader("textfile.txt"));
    String data = null;
    List inputs = new ArrayList();
    while ((data = in.readLine()) != null) {
      inputs.add(data);
    in.close();
    String[] lines = new String[0];
    lines = (String[]) inputs.toArray(lines);Untested, and exception handling and so forth omitted. I leave it to you to decide what to do with that array of Strings.
    PC&#178;

  • Help with downloading pdf/text files itunes

    Hi,
    I am trying to download and view the text/pdf files from this link: https://itunes.apple.com/us/course/statistics-110-probability/id502492375 (files 1, 4, 11 and so on.. )
    However, I am not able to open the text/pdf file from the downloads window on itunes. I use itunes on mac.
    I would appreciate your help.
    Thanks
    Parang

    parangsaraf wrote:
    Hi,
    I am trying to download and view the text/pdf files from this link: https://itunes.apple.com/us/course/statistics-110-probability/id502492375 (files 1, 4, 11 and so on.. )
    However, I am not able to open the text/pdf file from the downloads window on itunes. I use itunes on mac.
    You don't open it in the download window.
    Select iTunes U in the left sidebar.
    If you don't see the left sidebar, iTunes menu View > View sidebar.

  • Help with updating a database while in cfloop

    Greetings. I'm having some difficulties in updating a
    database using cfquery inside of a cfloop.
    Background:
    I've got a text file that I need to interpret, line for line,
    and then update an existing database with information from that
    text file. For example, the text file might say
    jdoe~103 Anywhere St.~East Nowhere~New Jersey~05784~
    asmith~8963 North St.~Crabapple Cove~Maine~01390~
    (etc...you get the idea)
    So, I use a CFFILE to read the file, and then calculate the
    number of lines (records to be updated in the database) using
    listlen / 5 (in this example). From there, I:
    <cfloop index="record" from="1" to "#numberoflines#">
    <cfloop index="field" from="1" to "5">
    <cfset position = ((record - 1) * 5) + field>
    <cfelseif field EQ 1>
    <cfset form.username =
    ListGetAt(newcontents,position,"~")>
    <cfelseif field EQ 2>
    <cfset form.street =
    ListGetAt(newcontents,position,"~")>
    (etc...through EQ 5)
    </cfloop>
    <cfquery name="updatedatabase"
    datasource="clientlist">
    UPDATE clients
    SET
    Street= '#form.street#',
    (etc)
    WHERE email = '#form.username#'
    </cfquery>
    </cfloop>
    The problem I am having is that it updates the very first
    record in the set of records to update, but then it does not update
    any subsequent records.
    Why?
    Sorry if the code is crude. Is there a better way of doing
    this? If so, great detail would be helpful :) Relatively new at
    this.
    -Brian

    quote:
    Originally posted by:
    Dan Bracuk
    Updating a db from a file using cold fusion is generally
    inefficient and should only be used as a last resort. If your db
    has any bulk loading/updating utilities, consider using them. Maybe
    you can use cold fusion to upload the file and ftp it to your db
    server or something like that.
    Better yet, that file has to come from somewhere. Is there a
    way you can update your db instead of generating a file in the
    first place?
    The file starts as an output generated by a web user (an
    administrator on the software) which creates a text file containing
    email addresses, one per line. An external process which I have no
    control over takes that file and generates another file containing
    information about each of those e-mail addresses (last name, first
    name, etc) one per line. I can't change that process. So, I'm left
    with an external text file that I need to parse and then put into
    the database...all through a web interface. The goal here is that
    an administrator of the software, who does not have direct access
    to the database, can (using cold fusion processing) update the
    database with new information on each e-mail address without my
    intervention.
    -Brian

  • Help with quality of exported files

    The problem: I'm trying to get a good quality, 34 minute movie onto a DVD with chapter markers separating individual short films. This is supposed to be a compilation of 8 family movies, in addition to an introduction and credits at the end. Four movies are old movies made in iMovie and are .m4v files. Four were made in FCE earlier this year. I linked everything together in a Master Sequence, putting pauses in between each with some livetype text files to introduce each video. The m4v files were imported and placed in the master sequence. The others are nested sequences. I put chapter markers at the beginning of each section. My intention was to export this one master sequence as a quick time movie, then put it into iDVD.
    It worked, but the quality was horrible! Everything became grainy, even the movies I had previously created in FCE. This was very disappointing. So I expertimented with a few things, and here’s what I found.
    When I exported a quicktime movie, the quality degraded. It became grainy. Also, it changed the aspect ratio and stretches everything horizontally, as if to take a standard size screen and stretch it to a widescreen. It did this even with the original movies I had made in FCE. I don’t like building self contained movies using this mode because the file sizes are too big, so when I export I tend to use quick time conversion. In this case, I was hoping a non-self contained movie would merely point to all the original content and not add compression artifacts (or something like that). It turns out it made it worse.
    When I tried to export a quicktime conversion, 640x480 VGA, best quality, H.264, the machine couldn’t do it. It ran for an hour or so and then crashed. Twice. That is for the entire movie. When I export individual clips (3-6 minutes) it works. The quality is good for movies made in FCE, not as good for imported m4v movies made long ago in iMovie, but better than what I get exporting quicktime movie files, either self contained or not. This is surprising to me, because I was expecting the export quick time movie command to produce the best quality. Also, I’m concerned that if I was able to create this, iDVD would not see any chapter markers anyway.
    So there is a problem either way. Experimenting has led me to discover several questions/issues which need answering:
    Issue #1: Why can’t I get a quick time movie of the same quality as what I see on the canvas, using the quick time movie export command? On a side note, the user's manual says something about a settings pop up menu where you can deselect the "recompress all frames" option. I can't seem to find this, and was thinking maybe that would help.
    Issue#2: Why do m4v files which are very high quality in iTunes suddenly become poor quality when imported into a sequence? Seems to be an import problem, because the movies are already grainy when they’re on the canvas. I thought about making XML files and importing them that way, but the original project files in iMovie are gone.
    Issue #3: Why do I end up with a stretched picture if I export quick time movies and there are mixed aspect ratio contents in the sequence (the m4v files are widescreen, the others are not)? More important, how to I get FCE to not do this?
    Issue #4: When I export movies using quick time movie (not conversion), the grainy movies actually look better when played in VLC. They also look good when opened with FCE. How can I get that kind of quality in quick time, or at least in iDVD? Perhaps that would solve my problem.
    Thanks for any help you can provide.
    E

    Thanks for the response. I’m not fluent with codecs or video compression, so this project quickly became more trouble than I expected.
    It turns out the nested sequences are not H.264, the compression field is blank for the nested sequences. I double checked and the other properties are correct. Sorry about that. The other movies, though, (ones built in iMovie for iTunes) are H.264.
    These four . m4v movies are in 960x540 and 480 x 272 because of the way they were exported in iMovie (Share -> Export Movie opens a menu with four sizes: Tiny 176 x 144, Mobile 480 x 272, Medium 640 x 360, and Large 960 x 540).
    I just imported the final products (what was exported from iMovie) as clips into FCE. Sounds like I should not be doing that. The original media is on my computer, but not the iMovie project files, and for what I’m trying to do it’s just not worth the time to rebuild the movies in FCE.
    Bottom Line: Here’s the current status of the project:
    All eight of the movies, by themselves, play well in quicktime. I can put all of them on a DVD, and they still play ok. I wanted to string them all together in one sequence, with some transitions in between (creating a “Play All” option on the DVD). That’s why I nested the sequences, and imported the movies made from iMovie, than added chapter markers. Unfortunately, putting these different types of media together and asking the computer to make one sequence is creating a mess. So I’m sticking with Plan B and putting the movies on a DVD without trying to merge them into a single track.
    A few follow up questions…
    Out of curiosity, when you say “convert everything to QuickTime DV NTSC 720x480 at 29.97fps with 48k audio,” do you mean the original media (all of the bits of video and stills that came from the camera) or the edited sequences I’m currently working with? As a lesson learned, should I be changing properties of clips before importing them to FCE, so the source material has consistent aspect ratios?
    The still images, though they are huge, show up with much better quality than the movies (which is expected, and I’m ok with). So I get a product which includes both video and still images, where the images are very sharp and the movie portions are a bit grainy (because they were taken on a small digital camera). If I change the size on the stills, won’t that just bring the still image quality down?
    I’m still baffled at why using the export quick time movie command makes a video of lower quality than when using quick time conversion (in other cases as well, not just this project). In every case, I’ve got digital pictures and movies from my digital camera, and some text in FCE or LiveType files on top of that, usually with additional audio tracks.

  • HT201541 I need help with updating my browser.

    I need help with updating my browser.  Its telling me that Safari is outdated.

    That is a very old version belonging to Snow Leopard. I take it you are not actually running Yosemite.
    Upgrading to Yosemite
    You can upgrade to Yosemite from Lion or directly from Snow Leopard. Yosemite can be downloaded from the Mac App Store for FREE.
    Upgrading to Yosemite
    To upgrade to Yosemite you must have Snow Leopard 10.6.8 or Lion installed. Download Yosemite from the App Store. Sign in using your Apple ID. Yosemite is free. The file is quite large, over 5 GBs, so allow some time to download. It would be preferable to use Ethernet because it is nearly four times faster than wireless.
        OS X Mavericks/Yosemite- System Requirements
          Macs that can be upgraded to OS X Yosemite
             1. iMac (Mid 2007 or newer) - Model Identifier 7,1 or later
             2. MacBook (Late 2008 Aluminum, or Early 2009 or newer) - Model Identifier 5,1 or later
             3. MacBook Pro (Mid/Late 2007 or newer) - Model Identifier 3,1 or later
             4. MacBook Air (Late 2008 or newer) - Model Identifier 2,1 or later
             5. Mac mini (Early 2009 or newer) - Model Identifier 3,1 or later
             6. Mac Pro (Early 2008 or newer) - Model Identifier 3,1 or later
             7. Xserve (Early 2009) - Model Identifier 3,1 or later
    To find the model identifier open System Profiler in the Utilities folder. It's displayed in the panel on the right.
         Are my applications compatible?
             See App Compatibility Table - RoaringApps.
    Upgrading to Lion
    If your computer does not meet the requirements to install Mavericks, it may still meet the requirements to install Lion.
    You can purchase Lion at the Online Apple Store. The cost is $19.99 (as it was before) plus tax.  It's a download. You will get an email containing a redemption code that you then use at the Mac App Store to download Lion. Save a copy of that installer to your Downloads folder because the installer deletes itself at the end of the installation.
         Lion System Requirements
           1. Mac computer with an Intel Core 2 Duo, Core i3, Core i5, Core i7,
               or Xeon processor
           2. 2GB of memory
           3. OS X v10.6.6 or later (v10.6.8 recommended)
           4. 7GB of available space
           5. Some features require an Apple ID; terms apply.

  • MAC OS 10.6.8 Using Safari 5.1 Needing Help With Updating Adobe Flash

    Hello-
    Recently Adobe Flash installed an icon in my System Preferences and when I click the icon there are several tabs.  One allows updates to check automatically.  It says it will install the latest version of Flash without having to remove the previous version, but I have never been told that a newer version is available unless I clcik "check now."  although "Check for updates automatically" is checked, I do not know where it tells me a newer version is available.  Also, there has been 5 "newer versions" available since this icon was installed in System Prefeences, I have only found out about the newer versions when I clicked "Check Now."  If I read that with this new way to install the latest Mac version of Flash does not require me to uninstall the previous version of Flash how do I install the most recent version of Flash?  Does it come in an email?
    Since it is not telling me that there is a more recent version of Flash unless I click "Check Now" should I still do it the way I used to install the latest version of flash?  (The way before this icon was added to System Preferences)?
    I would appreciate help with updating Flash to the most recent version.  I used to uninstall the older version, restart the browser and download the most recent version and install it.  It always worked find but this was before there was an Adobe icon in my system Preferences.

    Hello,
    The way you used to do this (uninstall, restart the browser, etc.) is still definitely valid and probably the "safest" way to get a new version installed.  Uninstalling shouldn't be required, but it definitely doesn't hurt.  If you feel comfortable doing it the old way, please feel free to continue using that process.
    As for notifications, this is a bit trickier, but in general you should be notified within 30 days (or so) after a new player is released.  This usually occurs when the browser loads swf content.  Clicking the button will, like you mention, immediately check.  Another alternative to finding out when a new player is released is to subscribe to our Flash Player Releases feed.
    Is there a way to be automatically notified when a new Flash Runtime release is made?
    Thanks,
    Chris

  • Help with updates for CS6

    I need help installing latest updates for CS6.  I have Win 7 and have tried updating from the Help - Updates menu.  The error is:  U43M1D207.

    Thanks for your response.  I am in the United States in So. Arizona.
    Date: Fri, 5 Oct 2012 12:21:45 -0600
    From: [email protected]
    To: [email protected]
    Subject: Help with updates for CS6
    Re: Help with updates for CS6 created by Jeff A Wright in Downloading, Installing, Setting Up - View the full discussion
    Crunkle1 you are welcome to work directly with our support team for guided assistance.  If you go to http://www.adobe.com/ and select Help and Contact Us you should be given the option to contact our support team via telephone.  Which country/region are you in?
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/4752605#4752605
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4752605#4752605
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4752605#4752605. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Downloading, Installing, Setting Up by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Help with converting a Nero file

    I have previously converted a dvd insert designed with Nero into a pdf using adobe acrobat in order to send to someone else.  When I tried to do the same thing today with a new Nero designed insert the conversion wouldn't work.  The message said adobe didn't support the program that created the file.  Any ideas?

    thanks for your response.
    When I create a dvd insert or cd label etc using Nero the file extension is nct - nero cover template.  The printer wants the file as a pdf as he can't open Nero files.  I have version 9.3 of acrobat.
    Date: Mon, 18 Jan 2010 21:43:47 -0700
    From: [email protected]
    To: [email protected]
    Subject: help with converting a Nero file
    Nero is simply a CD/DVD burning application and should have no effect on the type of files that will eventually be on the CD/DVD.
    What type of files are you trying to convert and exactly how are you trying to convert them? Plus, it would help to know the version of Acrobat you are using.
    >

  • I had to put my computer by together without migration or time machine I NEED help with order of the files?

    I had to put my computer by together without migration or time machine I NEED help with order of the files?

    Hi, where are these other files exactly?

  • Help with updates - The software change returned error code 0x87D00215(-2016411115).

    I have rolled out bunch of updates across few hundred workstation systems.
    Few of the desktops have failed to install SOME of the updates and just can't get my head around as to why?
    Looking at one of the workstations, I can see 5 updates are pending download at 0%.
    Some of these fail after a while and with in Software Centre, I can see 'Help with updates - The software change returned error code 0x87D00215(-2016411115).'. Not exactly sure what this means, but I have tried clearing the cache and
    rebooting the workstations few times.
    (I have also tried to use Windows Update and install one of these manually, which worked.)

    Investigating this further, I have found the following in CAS.log:
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {ED6E9E5C-E806-43CA-9F93-49AC72D1DEAD} for content 53bf87a2-bedf-4def-b0ec-9637613c3429.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting locations synchronously for content 99ddb078-b780-4605-8fac-9607fe56450d.1 with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    The number of discovered DPs(including Branch DP and Multicast) is 1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Calling back with the following distribution points ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Distribution Point='http://DPSERVER.com/SMS_DP_SMSPKG$/99ddb078-b780-4605-8fac-9607fe56450d', Locality='LOCAL' ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting content 99ddb078-b780-4605-8fac-9607fe56450d.1, size(KB) 0, under context System with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {67B7E59B-A386-4EA8-BF39-2EB64B108A6C} for content 99ddb078-b780-4605-8fac-9607fe56450d.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting locations synchronously for content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1 with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    The number of discovered DPs(including Branch DP and Multicast) is 1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Calling back with the following distribution points ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Distribution Point='http://DPSERVER.com/SMS_DP_SMSPKG$/61d33de7-9582-41e3-82fc-3e0f970b60f3', Locality='LOCAL' ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1, size(KB) 0, under context System with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {12E48136-B545-4C42-9745-9FF97CE38D52} for content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)

  • Need help with actively replacing text in SVG

    I am new to Dreamweaver, Illustrator and SVG.  Also, I do have a firm understanding of HTML but limited knowledge of Javascript and other languages.  I am trying to create a website where the user is able to type in a form field (or something to that extent) and have the text in a displayed SVG be updated with the typed text.  I've done extensive searching on the subject and come up with nothing that seems to work.  Nor do I seem to be able to make it work.
    I found a dead tutorial on the Adobe website which might help illustrate what I am trying to achieve:
    http://www.adobe.com/svg/basics/text.html
    ANY help would be GREATLY appreciated.
    Thank you
    Adam

    Select the text. Copy to Clipboard. Open TextEdit. Paste. Resize its window appropriately. Choose Print off its File menu. Done.

  • Help needed sorting a text file.

    I'm trying to simply open a file, which is a text file of a list of names, then sort that file, the print the sorted file. The problem is that I keep getting this error
    Exception in thread "main" java.util.NoSuchElementException: No line found
         at java.util.Scanner.nextLine(Unknown Source)
         at pro.NamesFile.main(NamesFile.java:36)
    Which is at this line[b] words= new String(inputFile.nextLine());
    It's not reading any lines from the file and I can't figure out why.
    Here's the rest of my code:
    public class NamesFile {
         public static void main(String[] args) throws FileNotFoundException {
              Scanner inputFile;
            inputFile = new Scanner(new File("C:/Documents and Settings/Cougar/Desktop/New Folder (2)/names.txt"));
            String name;
            inputFile.next();
            String[] words = new String[100];
            while (inputFile.hasNext()) {
                 name = inputFile.nextLine();     
                 for (int i = 0; i < words.length; i++) {
                      words[i] = new String(inputFile.nextLine());
            Sort2.insertionSort(words);
                 for (int index=0; index < words.length; index++)
                    System.out.print(words[index].toString()+"\t");
    }Here the sort algoritm I'm using, it the insertion sort one.
    public static void selectionSort (String[] list)
               int min;
               String temp;
               for (int index = 0; index < list.length-1; index++)
                  min = index;
                  for (int scan = index+1; scan < list.length; scan++)
                     if (list[scan].compareTo(list[min]) < 0)
                        min = scan;
                  // Swap the values
                  temp = list[min];
                  list[min] = list[index];
                  list[index] = temp;
            public static void insertionSort (String[] list)
               for (int index = 1; index < list.length; index++)
                    String key = list[index];
                  int position = index;
                  //  Shift larger values to the right
                  while (position > 0 && key.compareTo(list[position-1]) < 0)
                     list[position] = list[position-1];
                     position--;
                  list[position] = key;
            }I'm still relativly new at this, so forgive me if there's something obvious that I'm missing.And thanks for any help anybody can give me.

    You haven't gotten to running the sort yet, so I didn't even check that the sort routine is correct.
    Your problem is:
    You say inputFile.hasNext() once, and then you read 1 line from it. Then, in your 'for' loop, you read 100 lines from it. So, you always attempt to read 101 lines, even if the file is shorter than that.
    You should call "hasNext" before each call to "readLine". Also, you probably want a "while" loop, instead of a "for" loop, since you don't know how many words you will have. I assume you are expecting 100 or less (based on your array size).
    Two more notes:
    1. Don't do "new String(inputFile.readLine())". All you need is:
    words= inputFile.nextLine();
    2. You don't need toString here:
    System.out.print(words[index].toString()+"\t");words[index] is already a String, and concatenating the "\t" to words[index] would create a String, anyway, no matter what type words[index] was. And, calling:
    System.out.print(words[index]);would also automatically call "toString", even if words[index] were not a String.
    You could avoid creation of new Strings by:
    System.out.print(words[index]);
    System.out.print("\t");Just make sure you add braces around them, if both lines are the body of a 'for' loop. You should also make the second 'for' loop into a 'while' loop, using a counter that you update as you read the lines--so that you don't process the "null" elements of the array. You also need to account for null elements in your sort method.

  • 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!

  • Keeping edits when updating linked text file

    My main use of indesign is laying out text files that are created in work. They need be linked, becuase the authors of these files are constantly updating them.
    I place the file, and then format the tables to make them look better, and also sometimes add images into the text
    However, when the original changes, and I update the text box with the new text, all the formatting i've added is lost.
    This must be a common problem with linked files, so, if anyone has any recommendations please let me know. Most importantly would be a way to automatically apply / keep the stlying for the tables.

    You can try exporting to RTF and relinking those files back to your
    document and letting your writers work on those, but InCopy is far
    better solution.
    Why not download the demo and show them how much time they'll save with
    it? Or bring in a consultant who can demonstrate it. I've found that
    doing a demo can really open some eyes to the possibilities.
    Bob

Maybe you are looking for

  • Wants to activate batch management for a material which already had a Stock

    hi, i want to activate batch management for a material which already has a stock and open Purchasing documents. is there any way by which we can do it without removing the same. please help.

  • Why am I getting an alert every night at 9PM?

    Here's a weird issue. Starting a couple months ago, every night at exactly 9 PM, the default text alert sounds on my phone. And I can't figure out what's causing it. - No alarm is set. - No notifications pop up, either as a banner or alert. No badge

  • Who's using Oracle Text?

    Hi all, I've done some experimenting with Oracle Text, and it seems to offer some handy stuff. I am a bit disappointed with the quality of the INSO filtering technology, especially for PDFs. There are also some items that seem, at best, extremely dif

  • Fpga IO module clock with TRIG

    Hi, I'm working with the "IO module clock 0" at 100MHz. My problem is when I'm compiling, I get Error Place905. I found out that it's because I'm using a PXI trigger inside the timed loop. Is there a solution to use triggers with this clock?  I joine

  • Dynamic url in readonly with xml

    Hello everybody, The link works fine, but I do not want the field to be editable. And when the field is read only, the link no longer works because of the event Have you a solution for the field link can not be editable ? Sorry i speak french ;o) tha