Results 1 to 8 of 8
  1. #1
    biirdo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default Read text file into array instead of being hard coded in the script.

    Hi,

    Can anyone help please.

    I have a script which displays an array content to a marquee. I would like to use a text file ('data.txt') to load the data instead of having it hardcoded in the script.

    The part of the script I would like to replace is;

    var msgarray=new Array
    (
    'Message 1','Message 2','Message 3','Message 4'
    );


    Many thanks.

  2. #2
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    Hi biirdo,

    You could use the Scanner class in the java.util package for this. You can create it with a File object and then read lines from a file.

    Cheers,
    Erik

  3. #3
    biirdo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Hi, thanks for the reply. Can you give me an idea of how this might look please as I am not familiar with java? Many thanks

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by biirdo View Post
    Hi, thanks for the reply. Can you give me an idea of how this might look please as I am not familiar with java? Many thanks
    Your example code shows Javascript. Which one is it? Java or Javascript? Note that those two languages are quite different.

    kind regards,

    Jos

  5. #5
    biirdo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Hi, it's Javascript. Thanks

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by biirdo View Post
    Hi, it's Javascript. Thanks
    This is a Java forum; sorry; you have to find yourself a Javascript forum.

    kind regards,

    Jos

  7. #7
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    JavaRanch/CodeRanch has a subforum on JavaScript, so you might want to check them out.

  8. #8
    biirdo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Hi curmudgeon,

    I will take a look. Thanks for your help

    Biirdo

Similar Threads

  1. offline inspection is not reporting "Hard coded String" errors
    By g_madhu_krishna in forum IntelliJ IDEA
    Replies: 0
    Last Post: 09-17-2010, 08:02 AM
  2. Read Text File
    By Blackberrylerner in forum New To Java
    Replies: 6
    Last Post: 08-14-2010, 11:09 AM
  3. Signed Java Applet to read a file on hard drive?
    By ollyworks in forum Java Applets
    Replies: 2
    Last Post: 09-11-2009, 10:08 PM
  4. Read from a text file?
    By aaronfsimons in forum New To Java
    Replies: 3
    Last Post: 05-01-2009, 04:42 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM

Tags for this Thread

Posting Permissions

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