i have done up a method to return a string values of a textfile which is hosted on a site
but i cant seem to get the value out when i call the method
private String DownloadFromUrl() //this is the downloader method
{
String strFileContents = null;
try
{
String webURL = "http://www.example.net/test/file.txt";
URL url = new URL(webURL);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
//create a byte array
byte[] contents = new byte[1024];
int bytesRead=0;
while( (bytesRead = bis.read(contents)) != -1){
strFileContents += new String(contents, 0, bytesRead);
}
}
catch (IOException e)
{
}
return strFileContents;
}
i got a null pointer exception thrown from the stringreader
//Read text from file
StringBuilder text = new StringBuilder();
String test = DownloadFromUrl();
try {
StringReader sr = new StringReader(test);
String line="";
int c,counter =0;
while ((c = sr.read()) != -1)
{
line+=(char)c;
counter++;
}
char[] singleText = line.toCharArray();
for (int i = 0; i < counter; i++)
{
classifier(singleText[i]);
}
text.append(line);
}
catch (IOException e) {
//You'll need to add proper error handling here
}
i tested my code and the error was thrown form the stringreader with a null pointer
but works correctly when i test with a string text.
so the problem would lie on the DownloadFromUrl method not returning the string of text from the online .txt file
added the error message hope this helps


Try This to convert InputStream to String
}
}