Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

a file problem - pretty urgent  RSS feed

 
vivek sivakumar
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well in my java program in reading the contents of a file (say for ex: service.txt),
the contents of the txt file is like this
[Gvalue]
file=copy.xml
my program reads this and works well but what happens now is that when i comment out something in my txt file say like this
//[gvalue]
file =do.xml
[Gvalue]
file=copy.xml
then im getting a exception (java.lang.null) , i dont want my method to read the commented stuff
so kindly help me , my method is like this
public Vector getSectionNames() throws Exception {
Vector values = new Vector();
//Create the input stream for the file content
DataInputStream dis = new DataInputStream(
new StringBufferInputStream(this.fileContent));
//Read the content of the file line by line
String fromFile = null;
while ((fromFile = dis.readLine()) != null) {
//Check if the line contains [/]
if (fromFile.indexOf("[") >= 0 &&
fromFile.indexOf("]") > 0)
{
fromFile.trim();
values.addElement(fromFile.trim().substring(1, fromFile.length() - 1));
}
}
return values;
}
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vivek,
How about:

Regards,
Manfred.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!