Script to get the file content as string

Question: How do I get the content of a file as a string?

Answer: The following script (serverside Javascript in the SiteVision Script portlet) demonstrates the solution

// the file is located in the file repository in the folder Flash/js/

// the file name is 'swfobject.js'

//

var IoUtils = Packages.org.apache.commons.io.IOUtils,
utils = request.getAttribute('sitevision.utils'),
resourceLocator = utils.resourceLocatorUtil,
fileRepository = resourceLocator.fileRepository,
jsFile = fileRepository.getNode('Flash/js/swfobject.js'),
inputStream = jsFile.getProperty('URL').value.binary.stream;

 

try {
var asString = IoUtils.toString(inputStream);
out.println('' + asString);

} finally {
IoUtils.closeQuietly(inputStream);

}

Denna sida publicerades: 2016-11-14

Skriv ut PDF-avsnitt

Hjälpte informationen på den här sidan dig?

Missa inga nya rön, tips och tricks! Prenumerera på insite!

Find us!

SiteVision AB (Headquarter)
Vasagatan 10
702 10 Orebro
Sweden

Info: +46 19-17 30 30
Support: +46 19-17 30 39

Latest Tweets