Over a million developers have joined DZone.

Batch And Shell Script To Produce Java String From Text File

Knocked together batch / shell script to quickly convert SQL (or any text file) to a Java string (using StringBuilder). Put both the batch and the shell script into a directory on the path, add a shortcut to the batch file to your sendto folder, and then you can right click the file >> send to >> sqlify and notepad will pop up with your Java-ified text.

This requires Cygwin to be installed.

I'm sure it could be prettier, but it works.


cat %1 | sh sqlify.sh > %1.txt
notepad "%~1.txt"


echo "StringBuilder sqlBuilder = new StringBuilder();"
sed -e "s/^ */sqlBuilder.append(\"/g" -e "s/$/ \");/g" | unix2dos

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}