Problem reading a text file
I'm having problem accessing a text file within the dam. my file's path is content/dam/testing.txt. I'm trying to read and create a node for each line read.
Do I need to access the file under renditions? ie: /content/dam/testing.txt/jcr:content/renditions/original
Here is my code:
public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
WorkflowData workflowData = item.getWorkflowData();
if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) {
String path = workflowData.getPayload().toString();
String nodepath = workflowData.getPayload().toString() + "/jcr:content";
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Session jcrSession = session.adaptTo(Session.class);
Node jcrNode = (Node) jcrSession.getItem(path);
try
{
Resource rs = resourceResolver.getResource(path);
File file = rs.adaptTo(File.class);
BufferedReader br = new BufferedReader(new FileReader(file));
String sCurrentLine;
int r = 2;
String[] readarray = new String[r];
while ((sCurrentLine = br.readLine()) != null && r!=2) {
readarray[r] = sCurrentLine;
Node propNode = jcrNode.addNode("txtITEM", "nt:unstructured");
if (jcrNode != null) {
propNode.setProperty("line", readarray[r]);
jcrSession.save();
}
r++;
}
I took out the try statements for easy reading. Do I have to read this text file as a binary instead?..I'm adapting the resource as a file class.
Thanks