How to associate lines in a text file as an elements of the Vector?

Hi!
I have used BufferedReader(new FileReader(c:/java/MyText.txt)) to read from MyText.txt file. Now I know how to load content of this file (every line in file describes each photo in my photo-set) into a Vector. But how to associate lines of MyText.txt as an elements of the Vector?
Thanks Felipe for his help.
DM.

Thank you telism,
Let me tell you the whole story.
I'm trying to write an application which has to show my image files (set of photos) with a text description. The list of image files placed into the JList. So, when I select a file from the JList it shows me an image (everything is OK).
But, every image has it's text description in MyText.text file. It's a file with each text line for every image. Actually, I am trying to connect two actions - showing my image and setting it's specified text line description (from MyText.txt) in a JTextArea. I thought that the best way to do this with my text it is like I did it with my images through Vector. But No Success.
Can You help me on that? If You will show me how to do it on my example I will really appreciate it.
Thank You DM.
Here is my application:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
public class UnitA extends JPanel implements ListSelectionListener {
BasicUnitA Myapplet;
JPanel listPanel, picturePanel;
Vector imageNames1;
JList list1;
JLabel picture1;
JScrollPane listScrollPane1, pictureScrollPane1, TSP1;
JTextArea TA1;
int index;
UnitA (BasicUnitA parent, boolean p1, boolean p2) {
Myapplet=parent;
//Read image names from a properties file
ResourceBundle imageResource1;
try{
imageResource1 = ResourceBundle.getBundle("imagenames1");
String imageNamesString1 = imageResource1.getString("images");
imageNames1 = parseList(imageNamesString1);
} catch (MissingResourceException e) {
System.err.println("Please, add properties file with image names.");
System.exit(1);
//Create one list of images and put it in a scroll pane and panel
list1 = new JList(imageNames1);
list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list1.setSelectedIndex(0);
list1.addListSelectionListener(this);
listScrollPane1 = new JScrollPane(list1);
listScrollPane1.setPreferredSize(new Dimension (120,120));
//Set up the picture label and put it in a scroll pane
ImageIcon firstImage1 = new ImageIcon("java/Applications/images/fotos/" +
(String)imageNames1.firstElement());
picture1 = new JLabel(firstImage1);
picture1.setPreferredSize(new Dimension (firstImage1.getIconWidth(),
firstImage1.getIconHeight()));
pictureScrollPane1 = new JScrollPane(picture1);
pictureScrollPane1.setPreferredSize(new Dimension (500,360));
pictureScrollPane1.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(5,5,5,5)),
BorderFactory.createLineBorder(Color.black)));
pictureScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLL
BAR_ALWAYS);
TA1 = new JTextArea();
TA1.setLineWrap(true);
TA1.setWrapStyleWord(true);
TA1.setEditable(false);
TA1.setFont(new Font("Serif", Font.PLAIN, 16));
TSP1 = new JScrollPane(TA1);
TSP1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_
ALWAYS);
TSP1.setPreferredSize(new Dimension(500,40));
TSP1.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(5,5,5,5)),
BorderFactory.createLineBorder(Color.black)));
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) return;
JList theList1 = (JList)e.getSource();
if (theList1.isSelectionEmpty()) {
picture1.setIcon(null);
TA1.setText(null);
} else {
index = theList1.getSelectedIndex();
ImageIcon newImage1 = new
ImageIcon("java/Applications/images/fotos/" +
(String)imageNames1.elementAt(index));
picture1.setIcon(newImage1);
picture1.setPreferredSize(new Dimension (newImage1.getIconWidth(),
newImage1.getIconHeight()));
picture1.revalidate();
try{
BufferedReader reader = new
BufferedReader(new FileReader("c:/java/Applications/MyText.txt")));
String str;
while((str = reader.readLine()) != null) {
TA1.setText(TA1.getText()+str);
reader.close();
}catch(IOException evt){};
protected static Vector parseList(String theStringList) {
Vector v = new Vector(10);
StringTokenizer tokenizer = new StringTokenizer (theStringList, " ");
while (tokenizer.hasMoreTokens()) {
String image = tokenizer.nextToken();
v.addElement(image);
return v;

Similar Messages

  • File adapter-How to set line break in text file-split record into two lines

    Dear Guru's,
    I have to solve following problem with XML (with mulitiple records) to TEXT file scenario using file adapter. I have to output for ever ONE data record in XML always two identical lines in text file. Second line should have a little bit different mapping in few fields like date,... So I did duplicate fileds in my output structure in mapping and need to know how to set line break in the middle and see half of structure in first line and next structure half in second line
    My output structure in mapping is:
    CASHFLOW
    - INTERFACE
    - GESELLSCHAFT
    - ANWENDUNG
    - PRODUKT
    - VERTRAG
    - BETRAG
    - WAEHRUNG
    - DIRECTION
    - BEWEGUNGSTYP
    - FAELLIGKEIT
    - ZINSFESTSTELLUNG
    - ZAHLUNGSTAG
    - RENDITE
    - INTERFACE2
    - GESELLSCHAFT2
    - ANWENDUNG2
    - PRODUKT2
    - VERTRAG2
    - BETRAG2
    - WAEHRUNG2
    - DIRECTION2
    - BEWEGUNGSTYP2
    - FAELLIGKEIT2
    - ZINSFESTSTELLUNG2
    - ZAHLUNGSTAG2
    - RENDITE2
    Question is how can I set on receiving file adapter in Content Conversion Parameters that fields from first structure half INTERFACE...RENDITE should be outputed in one line and fields from second half of structure INTERFACE2...RENDITE2 should start on second line in final text file.
    I'm getting at the moment one line only and I need to know how can set line break so that second line starting with INTERFACE2(CA)...RENDITE2 will start in new line.
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000",CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    This should be final output:
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000"
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    My file adapter settings:
    RecordsetStructure=CASHFLOW
    CASHFLOW.fieldNames=INTERFACE,GESELLSCHAFT,ANWENDUNG,PRODUKT,VERTRAG,BETRAG,WAEHRUNG,DIRECTION,BEWEGUNGSTYP,FAELLIGKEIT,ZINSFESTSTELLUNG,ZAHLUNGSTAG,RENDITE
    CASHFLOW.fieldSeparator=,
    CASHFLOW.endSeparator='nl'
    CASHFLOW.fieldNames=INTERFACE2,GESELLSCHAFT2,ANWENDUNG2,PRODUKT2,VERTRAG2,BETRAG2,WAEHRUNG2,DIRECTION2,BEWEGUNGSTYP2,FAELLIGKEIT2,ZINSFESTSTELLUNG2,ZAHLUNGSTAG2,RENDITE2
    CASHFLOW.fieldSeparator=,
    It wont help if I add two identical structures in mapping because in output i would see for multiple entries section with first lines only and after that section with second lines only. And CASHFLOW is one part of more complex mapping ...
    (This is final output structure RecordsetStructure=HEADER,CASHFLOW,CONDITION,REFERENCE,CONTRACT - more sections with different data and all these should have duplicate lines at the end)
    Thanks a lot for any help
    Cheers
    Marian
    Edited by: Marian  Luscon on Jul 14, 2009 11:44 AM

    Hi Ivan,
    right, I did test just for sure.
    Putting constant 'nl' into field CASHFLOW-INTERFACE1 didnt help - still getting one line instead two lines.
    CA ,"0100" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,2 ,12 ,2009-01-28 ,2009-01-27 ,2009-01-28 ,"0.0000000" ,'nl' ,"GTP1" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,1 ,10 ,2009-01-27 ,2009-01-27 ,2009-01-27 ,"0.0000000"
    So there is still question. Is there any way (mapping,...) how to output always 2 lines in text file for one record in XML. It always does 1 record in mapping structure = 1 line but we need 2 lines ...
    Example:
    Input: 4 records in XML
    Output: 8 lines in final text file ...
    Thanks to you all guys
    Marian

  • Hi how to read lines in a text file???

    Hi experts
    please help me out
    i wanna read a file which contaning students id and name.
    such as
    211 john
    122 david
    111 Chris
    and so on.
    i know how to read using bufferedreder but the problem is
    my teacher is gonna change the number of students in the file
    when she marks my code....
    so i don't know how many lines(students) will it be.in the file.....
    in this case, how to read a file?? i don't know how many lines will it be..
    but i know the maximum students in the file is 20.
    how to do it with this..........................
    experts~ please help me~~~

    try this
    try {
                FileReader reader = new FileReader(f);
                BufferedReader bufferedReader = new BufferedReader(reader);
                line = bufferedReader.readLine();
                while (line !=null) {
                    line = bufferedReader.readLine();
                bufferedReader.close();
                reader.close();
            catch(IOException e) {
                String msg = new String("Error Reading " + f + " data file");
                throw new OpenFileException(msg);
            }

  • How to associate 1997-2003 Word doc files with Word 2010?

    Hi
    I am surprised not to be able to find out how to associate word 1997-2003 Word files with Wrod 2010. The object is to have Word 2010 open the document when I click on the document. Many of my Word 1997-2003 documents were created using Word 2010.
    When I try to use the associations function in Windows 7 I cannot find the Word program. Checking "Properties" on the Word Icon leads to a program called "CVH.EXE" which does nothing when I try to open doc files with it.
    Thank you.
    David
    lifeform23

    Hi,
    From your description , I understand that you want to open the prior Word doc files  in Word 2010.
    You can refer to the KB article that resolve this issue:
    How to open and save Word, Excel, and PowerPoint 2007 or 2010 files in earlier versions of Office programs
    http://support.microsoft.com/kb/924074
    Sincerely,
    Harry 

  • How can i read all the lines from a text file in specific places and use the data ?

    string[] lines = File.ReadAllLines(@"c:\wmiclasses\wmiclasses1.txt");
    for (int i = 0; i < lines.Length; i++)
    if (lines[i].StartsWith("ComboBox"))
    And this is how the text file content look like:
    ComboBox Name cmbxOption
    Classes Win32_1394Controller
    Classes Win32_1394ControllerDevice
    ComboBox Name cmbxStorage
    Classes Win32_LogicalFileSecuritySetting
    Classes Win32_TapeDrive
    What i need to do is some things:
    1. Each time the line start with ComboBox then to get only the ComboBox name from the line for example cmbxOption.
       Since i have already this ComboBoxes in my form1 designer i need to identify where the cmbxOption start and end and when the next ComboBox start cmbxStorage.
    2. To get all the lines of the current ComboBox for example this lines belong to cmbxOption:
    Classes Win32_1394Controller
    Classes Win32_1394ControllerDevice
    3. To create from each line a Key and Value for example from the line:
    Classes Win32_1394Controller
    Then the key will be Win32_1394Controller and the value will be only 1394Controller
    Then the second line key Win32_1394ControllerDevice and value only 1394ControllerDevice
    4. To add to the correct belonging ComboBox only the value 1394Controller.
    5. To make that when i select in the ComboBox for example in cmbxOption the item 1394Controller it will act like i selected Win32_1394Controller.
    For example in this event:
    private void cmbxOption_SelectedIndexChanged(object sender, EventArgs e)
    InsertInfo(cmbxOption.SelectedItem.ToString(), ref lstDisplayHardware, chkHardware.Checked);
    In need that the SelectedItem will be Win32_1394Controller but the user will see in the cmbxOption only 1394Controller without the Win32_
    This is the start of the method InsertInfo
    private void InsertInfo(string Key, ref ListView lst, bool DontInsertNull)
    That's why i need that the Key will be Win32_1394Controller but i want that the user will see in the ComboBox only 1394Controller without the Win32_

    Hello,
    Here is a running start on getting specific lines in the case lines starting with ComboBox. I took your data and placed it into a text file named TextFile1.txt in the bin\debug folder. Code below was done in
    a console app.
    using System;
    using System.IO;
    using System.Linq;
    namespace ConsoleApplication1
    internal class Program
    private static void Main(string[] args)
    var result =
    from T in File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TextFile1.txt"))
    .Select((line, index) => new { Line = line, Index = index })
    .Where((s) => s.Line.StartsWith("ComboBox"))
    select T
    ).ToList();
    if (result.Count > 0)
    foreach (var item in result)
    Console.WriteLine("Line: {0} Data: {1}", item.Index, item.Line);
    Console.ReadLine();
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions.

  • How to insert new line in a text file

    hi all,
    i wnat to know how can i insert a new line in a text file using java.
    for example i want the formate of the text like this
    1 2 3
    4 5 6
    until now i know only how to insert data but not new line.
    Thanks in advandce

    Hi you can put a new line in a text file using System.getProperty("line.separator"). This implementation will work for every OS.
    import java.io.*;
    class Demo{
    public static void main(String args[]) throws Exception {
    FileWriter fr = new FileWriter("FileDemo.txt");
         fr.write("AAAAAAAAAA");
    fr.write(System.getProperty("line.separator"));
    fr.write("AAAAAAAAAAA");
    fr.close();
    }

  • How can I find out the number of lines in a text file?

    How can I find out the number of lines in a text file?

    java.io.BufferedReader in = new java.io.BufferedReader( new java.io.FileReader( "YourFile.txt" ) );
    int lineCount = 0;
    while( in.readLine() != null )
    lineCount ++;
    System.out.println( "Line Count = " + lineCount );

  • How to read every line from a text file???

    How can i read every line from my text file ("eka.txt")
    now it only reads the first line and prints it out.
    What is wrong with this?
    import java.io.*;
    import java.util.*;
    class Testi{
         public static void main(String []args)throws IOException {
         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    File inputFile = new File ("eka.txt");
    FileReader fis =new FileReader(inputFile);
    BufferedReader bis = new BufferedReader(fis);
    String test=bis.readLine();
    String tmp= "";
    while((bis.readLine().trim() != null)) {
    int spacefound=0;
    int l=test.indexOf(" ");
         for(int i=0;i<test.length();i++){
         char c=test.charAt(i);
         if(c!=' ') tmp+=""+c;
         if(c==' ' && (spacefound<1) && !(tmp.equals(""))){
         tmp+=""+c;
         spacefound++;
         if(tmp.length()==l) {
         System.out.println(tmp);
         tmp="";
         spacefound=0;
         if(tmp.length()<l){
         for(int i=0;i<=(l-tmp.length());i++)
         tmp+=""+' ';
         System.out.println(tmp);

    Try this code, Hope it servers your purpose.
    import java.io.*;
    import java.util.*;
    class Testi {
         public static void main(String []args)throws IOException {
              BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
              File inputFile = new File ("Eka.txt");
              FileReader fis =new FileReader(inputFile);
              BufferedReader bis = new BufferedReader(fis);
              String test=bis.readLine();
              while(test != null) {
                   StringTokenizer st = new StringTokenizer(test," ");
                   while(st.hasMoreTokens())
                        System.out.println(st.nextToken());
                   test = bis.readLine();
    }Sudha

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • How do i read complete line from a text file in j2me?????

    how do i read complete line from a text file in j2me????? I wanna read file line by line not char by char..Even i tried with readUTF of datainputstream to read word by word but i got UTFDataFormatException.. Please solve my problem.. Thanks in advance..

    That is not my problem . i already read it char by char.. i am getting complete line..But this process is taking to much time..So thats why i directly wanna read complete line or word to save time..

  • How to add an space for every line in a text file in 46.B?

    Hi Friends!!
    My problem is the following,
    I need to add spaces in all lines of a text file
    Ej.'ABC ' , I'm using GUI_DOWNLOAD to download the internal table, but the function truncates all spaces, as it is 46B doesn't have the option for allowing the spaces at the end of each line,
    Do you know what can I do?? is there any other function module I could use?? I also tried with WS_DOWNLOAD but it didn't help!
    Thanks so much in advance!!!
    Frinee

    This a short example:
    data: begin of mytable occurs 0,
            line(2),
            lspace type x value '20',
            lenter type x value '0D0A',
          end of mytable.
    mytable-line = '1'.
    condense mytable-line.
    append mytable.
    mytable-line = '2'.
    condense mytable-line.
    append mytable.
    mytable-line = '3'.
    condense mytable-line.
    append mytable.
    call function 'GUI_DOWNLOAD'
         EXPORTING
           BIN_FILESIZE = 50
            FILENAME = 'C:\mybinfile.txt'
            FILETYPE = 'BIN'
         TABLES
            DATA_TAB = mytable
         EXCEPTIONS
           others = 9.

  • How to read specific lines from a text file using external table or any other method?

    Hi,
    I have a text file with delimited data, I have to pick only odd number rows and load into a table...
    Ex:
    row1:  1,2,2,3,3,34,4,4,4,5,5,5,,,5  ( have to load only this row)
    row2:   8,9,878,78,657,575,7,5,,,7,7
    Hope this is enough..
    I am using Oracle 11.2.0 version...
    Thanks

    There are various ways to do this.  I would be inclined to use SQL*Loader.  That way you can load it from the client or the server and you can use a SQL*Loader sequence to preserve the row order in the text file.  I would load the whole row as a varray into a staging table, then use the TABLE and MOD functions to load the individual numbers from only the odd rows.  Please see the demonstration below.
    SCOTT@orcl12c> HOST TYPE text_file.csv
    1,2,2,3,3,34,4,4,4,5,5,5,,,5
    8,9,878,78,657,575,7,5,,,7,7
    101,201
    102,202
    SCOTT@orcl12c> HOST TYPE test.ctl
    LOAD DATA
    INFILE text_file.csv
    INTO TABLE staging
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    (whole_row VARRAY TERMINATED BY '/n' (x INTEGER EXTERNAL),
    rn SEQUENCE)
    SCOTT@orcl12c> CREATE TABLE staging
      2    (rn         NUMBER,
      3     whole_row  SYS.OdciNumberList)
      4  /
    Table created.
    SCOTT@orcl12c> HOST SQLLDR scott/tiger CONTROL=test.ctl LOG=test.log
    SQL*Loader: Release 12.1.0.1.0 - Production on Tue Aug 27 13:48:37 2013
    Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
    Path used:      Conventional
    Commit point reached - logical record count 4
    Table STAGING:
      4 Rows successfully loaded.
    Check the log file:
      test.log
    for more information about the load.
    SCOTT@orcl12c> CREATE TABLE a_table
      2    (rn       NUMBER,
      3     data  NUMBER)
      4  /
    Table created.
    SCOTT@orcl12c> INSERT INTO a_table (rn, data)
      2  SELECT s.rn,
      3         t.COLUMN_VALUE data
      4  FROM   staging s,
      5         TABLE (s.whole_row) t
      6  WHERE  MOD (rn, 2) != 0
      7  /
    17 rows created.
    SCOTT@orcl12c> SELECT * FROM a_table
      2  /
            RN       DATA
             1          1
             1          2
             1          2
             1          3
             1          3
             1         34
             1          4
             1          4
             1          4
             1          5
             1          5
             1          5
             1
             1
             1          5
             3        101
             3        201
    17 rows selected.

  • Delete lines from a text file

    i need to delete (or replace them with white space) a few lines from a text file. I have a text file with first few lines & last few lines containing "<"or ">". I need to delete/replace with white space, the entire line. i need to do this urgently
    Could some one please tell me how to do this?

    the file can be of size 8MB or more. i get this file
    every week from a third party. So the size is not
    constant. I need to remove/replace with white space,
    the fist & last few lines and the rest is comma
    seperated values which i need to load to database
    using sqlldr. But still not sure abt how to remove
    the first few lines.
    i need to read this file, replace the lines as i read
    them and write the replaced string back to the file &
    then load the rest of lines to database.8 MByte is fairly small. Read the file a line at a time and copy to a new file only the lines you want. Should take no more than a second or so.
    P.S. It will probably be a mistake if you try to edit the original file in place.

  • How to read characters from a text file in java program ?

    Sir,
    I have to read the characters m to z listed in a text file .
    I must compare the character read from the file.
    And if any of the characters between m to z is matched i have to replace it with a hexadecimal value.
    Any help or suggesstions in this regard would be very useful.
    Thanking you,
    khurram

    Hai,
    The requirement is like this
    There is an input file, the contents of the file are as follows, you can assume any name for the file.
    #Character mappings for Japanese Shift-JIS character set
    #ASCII character Mapped Shift-JIS character
    m 227,128,133 #Half width katakana letter small m
    n 227,128,134 #Half width katakana letter small n
    o 227,129,129
    p 227,129,130
    q 227,129,131
    r 227,129,132
    s 227,129,133
    t 227,129,134
    u 227,129,135
    v 227,129,136
    w 227,129,137
    x 227,129,138
    y 227,129,139
    z 227,129,142
    The contents of the above file are to be read as input.
    On encountering any character between m to z, i have to do a replacement with a hexadecimal code point value for the multibyte representation in the second column in the input file.
    I have the code to get the unicode codepoint value from the multibyte representation, but not from a file.
    So if you could please tell me how to get the characters in the second column, it would be very useful for me.
    The character # is used to represent the beginning of a comment in the input file.
    And comment lines are to be ignored while reading the file.
    Say i have a string str="message";
    then i should replace the m with the unicode code point value.
    Thanking you,
    khurram

  • Passing lines in a text file to an array

    Hi,
    I did a search on this, looked through the tutorials. I want to read in a line from a text file and pass it to an array. here's my code:
    package pack1;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.util.Scanner;
    public class CDSort {
          * write a program that will read a bunch of cd's from a textfile,
          * count how many there are, and figure out how many cd boxes I will need based
          * on a fixed amount that will fit in each box. The cd's should be sorted alphabetically,
          * and each should be placed in a numbered box, and have a numbered position within that box
         public static void main(String[] args)throws Exception {
              java.io.File cdlist = new java.io.File("files/cd-list.txt");
              FileReader infile = new FileReader(cdlist);
              FileWriter outfile = new FileWriter("files/newlist.txt");
              if (cdlist.exists()){
                   System.out.println( cdlist.getName() + " exists at " + cdlist.getAbsolutePath());
                   System.out.println("this file was last modified on: " + new java.util.Date(cdlist.lastModified()));
                   int c;
                   while ((c = infile.read()) != -1) {
                        System.out.println(c);
                        String [] textArray = new String[99];
                             for(int i =0; i<textArray.length; i++){
                                  // trying to pass text to array here: I tried this, but got an error:
                                  //textArray[i] = infile.read(c);
                                  // i added this statement so I could see what the value of the array was on the console
                                  System.out.println(textArray[i] + i);
                        outfile.write(c);
                   infile.close();
                   outfile.close();
              } else
                   System.exit(0);
    }This is probably a pretty basic question, but my hunting arround hasn't really yielded anything.

    okay, here's what I did, this seems to work.
    package pack1;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.PrintStream;
    public class CDSort {
          * write a program that will read a bunch of cd's from a textfile,
          * count how many there are, and figure out how many cd boxes I will need based
          * on a fixed amount that will fit in each box. The cd's should be sorted alphabetically,
          * and each should be placed in a numbered box, and have a numbered position within that box
         public static void main(String[] args)throws Exception {
              java.io.File cdlist = new java.io.File("cd-list.txt");
              FileReader infile = new FileReader(cdlist);
              //FileWriter outfile = new FileWriter("newlist.txt");
              BufferedReader br = new BufferedReader(infile);
              BufferedWriter out = new BufferedWriter(new FileWriter("newlist.txt"));
              if (cdlist.exists()){
                   System.out.println( cdlist.getName() + " exists at " + cdlist.getAbsolutePath());
                   System.out.println("this file was last modified on: " + new java.util.Date(cdlist.lastModified()));
                   // while loop was here, I removed it.
                   String [] textArray = new String[99];
                   String line;
                   int lineNum = 0;
                   while ((line = br.readLine()) != null){
                        textArray[lineNum++] = line;
                        System.out.println(line);
                   int numOfCds = 1;
                   int boxNum = 1;
                   int boxPos = 1;
                   int cdsPerBox = 20;
                   out.write("Contents of Box " + boxNum);
                   out.newLine();
                   out.newLine();
                   for(int i = 0; i<textArray.length; i++){
                        out.write(textArray[i] + " box position: " + boxPos + "\n");
                        out.newLine();
                        boxPos++;
                        numOfCds++;
                        if (boxPos >= cdsPerBox){
                             boxNum++;
                             out.newLine();
                             out.newLine();
                             out.write("Contents of Box " + boxNum);
                             out.newLine();
                             out.newLine();
                             boxPos = 1;
                   infile.close();
                   out.close();
              } else {
                   System.out.println("file not found, program terminating");
                   System.exit(0);
    }thanks for all your help.
    bp

Maybe you are looking for