I have a spring batch service containing a FileItemReader,FileItemProcessor and FileItemWriter.When creating the FileItemWriter I have to set the Resource that will be my output file.
I am running the batch service on websphere on a Linux machine.The problem is if I set the resource as new FileSystemResource(new File("opt\temp1\myFile.txt")), the path of the file created is "/usr/IBM/WebSphere/AppServer/profiles/AppSrv01/\opt\temp\myFile.txt" which is not what I want.The path where I want to put the file is "\opt\temp\myFile.txt" on the linux file system.Any suggestions as to what I am doing wrong?.
Please see below the snippet where I am doing this.I am extending the FileItemWriter and overriding the open method to set the resource. Many Thanks.
@Override
public void open (ExecutionContext context)
{
String fileName = UUID.randomUUID ().toString ();
String filePath = fileLocation + fileName;
resource = new FileSystemResource (new File (filePath));
setResource (resource);
super.open (context);
}
fileLocation = "\opt\temp\", fileName="myFile.txt"
You are using backslashes in the value of fileLocation
. They are valid file name characters in linux. You should change the path to /opt/temp/
.