Results 1 to 2 of 2

Thread: Java array's

  1. #1

  2. #2

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    This code would read strings from a .txt file and store
    them in a String array. I just opted to print the contents
    of the array right away. The code is limited in the respect that you would have to know how long the file
    would be before you run it. or an Arrayoutofbounds
    error will occur. But you get the idea....... still check out
    the fill methods ive never used them but i think they would be easier to use.




    import java.util.Arrays.*;
    import java.io.*;

    class Stringfiller{
    public static void main(String[] args){

    try {
    BufferedReader buff = new BufferedReader(new FileReader("C:\\Java\\passwords.txt"));

    String[] k = new String[8];
    int i = 0;

    while(true){
    if(i >= 8) break;
    String s = buff.readLine();
    k[i] = s;
    System.out.println(k[i]);
    i++;
    }
    }catch(Exception e){System.err.println(e);}
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width