I suspect that you may have a misconception about what value is stored in your variable. So let me clarify exactly what is going on in your batch file.
set keyvalue=^&Type TestDoc.txt
echo %keyvalue% /// This is printing the right value.
That is not printing the right value. What you have done is assigned the value &Type TestDoc.txt
to the variable. When you then type echo %keyvalue%
, this line gets expanded to the following line:
echo &Type TestDoc.txt
This is actually two separate commands. The first, echo
, simply queries if the echo setting is currently on or off. The second command, Type TestDoc.txt
, is then executed.
At no point does the variable keyvalue
ever contain the contents of the file.
So when you have this line in your batch:
java -jar ErrorUpdate.jar "%keyvalue%"
It gets expanded to:
java -jar ErrorUpdate.jar "&Type TestDoc.txt"
This time, the &
is enclosed in quotes, so it does not act as a statement separator, but instead is passed to your java class's main method. Your main method just sees the string "&Type TestDoc.txt"
passed in as args[0]
.
If you want the java application to receive the full contents of the file, you need to make your java application read the contents itself.