Read File That Is String -> Integer (Assigning Value In Code)

Posted on 2004-11-20
Last Modified: 2010-03-31
Hello Team,
I have an issue with reading a string from a "file" called file.txt and turning it into a integer value.

Of you look below - i'm reading data from a file called file.txt and storing the data into an arraylist.

The first line in that text file says
priority  = 5;
It must say this on the first line. (it is a configuration file basically)

What i need to do in the code is make priority *the variable* equal to 5, but it come in as a string.
The data is in an arraylist  - so if try to print sl.get(0); I see that it's captured "priority = 5" as a string, but what i don't need
is the "priority =" part and the semi colon at the end. Just the 5, how do I get ?

See code below.
Thanks kindly

class MyThreadGroupFactory {
//Thread Group Object which will set the maximum priority for all even threads.

    private ThreadGroup threadGroup = null;
    private static MyThreadGroupFactory instance = new MyThreadGroupFactory();
    int priority = 1;

    private MyThreadGroupFactory()
    threadGroup = new ThreadGroup("Event Group");
    StringList sl = new StringList();"file.txt");

    threadGroup.setMaxPriority(priority); //<============================ "SETTING PRIORITY HERE"
    public static ThreadGroup getThreadGroup()
        return instance.threadGroup;

class StringList extends ArrayList {

//Constructor for the StringList object

  public StringList() {

  public void read(InputStream in) {
    read(new InputStreamReader(in));

  public void read(Reader r) {
    String line = null;
    BufferedReader in = null;
    try {
      in = new BufferedReader(r);
      while ((line = in.readLine()) != null) {
    catch (IOException e) {
    finally {
      try {
      catch (IOException e) {


  public void read(String fileName) {
    try {
      read(new FileReader(fileName));
    catch(IOException e) {


Question by:pauldhadialla
    1 Comment
    LVL 13

    Accepted Solution

    easy, for example if ur file is a single line as u described contains only the line u mentioned then just try this:

     int periority = 0;
    String line = sl.get(0);
    String[] splited = line.split("[/s=;]");
    if(splited.length > 1)
       periority = Integer.parseInt( splited[1].trim() );

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Title # Comments Views Activity
    Fix45 challenge 15 65
    powerN  challenge 3 31
    Books that can get me started on JAVA 2 33
    countAbc challenge 9 35
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now