0
public class TransactedFileCopy {
public static void main(String[] args) throws IOException{
    final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FileAppender.class);
    LoggerFacade loggerFacade = new Log4jLogger(logger);
    String tempDir = "c:/TransactedFileCopy";
    String tempDirOut = "c:/TransactedFileCopy/out";
    FileResourceManager frm = new FileResourceManager(tempDir, tempDirOut, false, loggerFacade);
    String storedir = frm.getStoreDir();
    String workdir = frm.getWorkDir();
    OutputStream outputStream;
        Object txId = null;
        try {
            frm.start();
            txId = frm.generatedUniqueTxId();
            frm.startTransaction(txId);   
            frm.copyResource(txId, storedir, workdir, true);
            frm.commitTransaction(txId);
        }
        catch (Exception e) {
            throw new IOException("DB rollback");
        }
    }
}

I am doing the same as Apache Transaction:write file transactionally - how to use resourceId but I have the following exception.

org.apache.commons.transaction.file.ResourceManagerSystemException: 
16ad53e99b9-0: 
Can not write to resource at 
'C:/Temp/TransactedFileCopy/out/Assures.Service- 
20180711.log' (ERR_SYSTEM)
Caused by: java.io.IOException: The filename, directory name, or volume 
label syntax 
   is incorrect
   at java.io.WinNTFileSystem.createFileExclusively(Native Method)
   at java.io.File.createNewFile(File.java:1012)
    at 


org.apache.commons.transaction.util.FileHelper.createFile(FileHelper.java:75) at
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Suneel Kumar
  • 11
  • 1
  • 4
  • Please, even if you're using code from another answer, write your actual code and inputs in here as well. – Federico klez Culloca May 20 '19 at 14:40
  • 1
    Is it normal that you are using / instead of \ on Windows ? – iXô May 20 '19 at 14:40
  • @iXô yes, it is acceptable. You can try that in the command prompt and it will work. – Federico klez Culloca May 20 '19 at 14:41
  • added my code to the question – Suneel Kumar May 20 '19 at 14:59
  • You seem to try copying directories (`getStoreDir()` and `getWorkDir()` suggest that) while documentation (http://commons.apache.org/proper/commons-transaction/apidocs/org/apache/commons/transaction/file/FileResourceManager.html) explicitly says that *Resource identifiers need a reasonsable string representation obtainable by toString. More specifically, they will have to resolve to a valid file path that does note denote a directory. If it does, you might be able to create it, but not to read or write anything from resp. to it.* which is a bit broken English, but still possible to decipher. – tevemadar May 20 '19 at 15:26
  • OK, my requirement is very simple, I would like to copy the files from one shared folder to another shared folder in a transaction. Is there any library available in java to achieve this? – Suneel Kumar May 21 '19 at 08:36

0 Answers0