Spring batch FileItemWriter not creating file at correct path

Tags: , , , ,

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(“opttemp1myFile.txt”)), the path of the file created is “/usr/IBM/WebSphere/AppServer/profiles/AppSrv01/opttempmyFile.txt” which is not what I want.The path where I want to put the file is “opttempmyFile.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.

    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 = “opttemp”, 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/.

Source: stackoverflow