Solved

Space assigning or printing error

Posted on 2008-10-28
3
237 Views
Last Modified: 2012-05-05
Hello,
I have this line of code: closingRootElement =("</"+rootElement.substring(1,rootElement.length())+">");
and when I print it; pw.print(closingRootElement);
pw is; PrintWriter pw = new PrintWriter(new FileWriter(tempFile));

What I get is:</CorrelationEngineParameters >   There is a space between the s and >, i.e., "s >".
I can not figure out from where this space is coming from.
Any thoughts, suggestions?
0
Comment
Question by:chima
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22826060
How is it parsing the rootElement string in the first place?

To fix the problem, you could change code to add trim() function; however, think you want to know what caused it.
closingRootElement =("</"+rootElement.substring(1,rootElement.length()).trim()+">");

Open in new window

0
 

Author Closing Comment

by:chima
ID: 31510929
Dame your good!  Had to add a -1 to the parser;
rootElement = (line.trim().substring(line.trim().indexOf('<'), (line.trim().indexOf("xmlns=")-1)));      
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22826784
<<<<<
Grading Comments:
Dame your good! Had to add a -1 to the parser;
rootElement = (line.trim().substring(line.trim().indexOf('<'), (line.trim().indexOf("xmlns=")-1)));
>>>>>

You got it.  Since there is a space before the xmlns attribute in the tag. :)

Glad to help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 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

22 Experts available now in Live!

Get 1:1 Help Now