File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Passing string as arg to main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing string as arg to main" Watch "Passing string as arg to main" New topic

Passing string as arg to main

sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
I want to pass in a long string that is xml format as an arg to the main. But I get errors that say "Encountered EOF after : ""

My string looks like this:

How do I fix this problem?
Henry Wong

Joined: Sep 28, 2004
Posts: 20380

Passing in a long strings is not a problem -- I have read megabyte strings from files and passed it to methods, and it works fine.

I am guessing that you are using a string literal, and forgot to escape the quotes.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Are you sure you want to pass it as an argument? longer pieces of text (especially if it's xml) should be read from a file and you only provide the lookup point as an argument.

JDBCSupport - An easy to use, light-weight JDBC framework -
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
Sounds like a good idea!
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
I'm not sure if it is a platform independent solution but on Windows it works:
Put the whole text between "" and put a \ in front of every " in the text:

"# @prefix wwtts: <http://localhost/ontologies/wwtts.owl#> . @prefix rdf: <>
. :i1 a wwtts:Incident . :i1 wwtts:incidVessel :v2 .:i1 wwtts:incidOccurRegion \"INDONESIA\" . :v2 wwtts:vesselFlag \"US\" . :v2
wwtts:vesselName \"BIG BERTHA\" . :v2 wwtts:vesselWeight 2953 .:p3 a wwtts:Alarm .:p3 wwtts:featurerawtext \"alarms\" .
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
That is strange. I thought I tried it with the "\" in front of the ". This time it worked.
I am actually passing the string to a web service from a client. But now I am not sure
how to extract the string returned.

I am getting a getStringResponse object which when I do a toString does not seem to
return a string although it is supposed to. I will post it to the web services group, unless you
have any suggestions.


I agree. Here's the link:
subject: Passing string as arg to main
It's not a secret anymore!