Hello everyone..

I am trying to retrieve a URL of applications from a text file...

My text file contains 3 URLS for 3 applications say for example :

C:/ABC.java
C:/JVM.java
C:/Tomcat.java

I have tried implementing a code for the same but when I try to copy the URL into a string variable it functions abruptly...

When i try to print it, it gives unnecessary spaces and the output is not desirable..
However, if I print it character wise, I do get the required result but I am unable to retrieve one URL at a time...It prints all the 3..

Any help???

I will write down the code that I have tried to implement...

//read.java

import java.io.*;

class read {
    public static void main(String args[])
    throws IOException
    {
        int m=0;
        int i;
        String s1 = new String() ;
        char c[] = new char[50];    
        FileInputStream fin;

        try {
            fin = new FileInputStream("C:/Documents and Settings/Administrator/Desktop/Shweta_Project/Work_27_Jan_2008/URL.txt");
        } catch(FileNotFoundException e) {
            System.out.println("File not found");
            return;
        } catch(ArrayIndexOutOfBoundsException e) {
            System.out.println("Usage : ShowFile File");
            return;
        }

        do {
            i = fin.read();
            if(i != -1) {

                char ch = (char) i;
                    c[m] = ch;
                    m++;
                if(c[m-1] == '*') {
                        c[m-1] = ' ';
                        s1 = new String(c);
                        System.out.print(s1);

                        s1 = null;
                            m=0;            
                }
            }
        } while(i != -1);
        fin.close();
    }
}


// MY FILE CONTENTS :
C:/ABC.java*
C:/JVM.java*
C:/Tomcat.java*

Please do help me...

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I would also suggest using String.trim(), might resolve the erroneous spaces you said you were receiving.

This article has been dead for over six months. Start a new discussion instead.