带文件附件

时间:2016-12-12 07:13:14

标签: java

我的程序将为任何传入的新文件执行文件夹监视(源文件夹),如果有任何传入的新文件,它将检测到新文件,并移动到另一个目录,即文件夹目的地。在它移动到目标文件夹之前,它将检查文件状态以确定文件复制状态的完成。为了我自己的测试目的,我使用了复制和粘贴到源文件夹。一切顺利,直到文件移动到目标文件夹,我的程序将从目标文件夹中取出文件并通过API调用发送它但我在编译器中收到此错误消息

The new file in source folder :pdf-sample.pdfEvent :ENTRY_CREATE
Start checking the file copy status
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
In Copy ProcessC:\User\source\pdf-sample.pdf (The process cannot access the file because it is being used by another process)
Finish copy

File size :7945

File Name :pdf-sample.pdf
Start to copy file to destination folder
Completed
file size in destination folder:7945
file name in destination folder:pdf-sample.pdf
file dir :C://REST API//destination//pdf-sample.pdf
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.james.mime4j.message.Header.addField(Lorg/apache/james/mime4j/parser/Field;)V
    at org.apache.http.entity.mime.FormBodyPart.addField(FormBodyPart.java:105)
    at org.apache.http.entity.mime.FormBodyPart.generateContentDisp(FormBodyPart.java:83)
    at org.apache.http.entity.mime.FormBodyPart.<init>(FormBodyPart.java:64)
    at org.apache.http.entity.mime.MultipartEntityBuilder.addPart(MultipartEntityBuilder.java:116)
    at fileStatus.fileStatus.pass(fileStatus.java:252)
    at fileStatus.fileStatus.main(fileStatus.java:81) 



这是我将文件移动到目标文件夹的代码,下面的代码将检查文件的状态(正在进行复制或完成复制), pass()方法将传递文件名和文件size用于指示需要通过API调用发送到服务器的文件

                while(true)
                    {
                        File file = new File(FilePath);
                        if ( file.exists())
                        {
                            RandomAccessFile statusCheck = null;
                                try 
                                {
                                    statusCheck = new RandomAccessFile(file,"r");
                                    if(statusCheck != null)
                                    {
                                        long filebyte = file.length();
                                        String filename = file.getName();
                                        System.out.println("Finish copy");
                                        System.out.println("\nFile size :"+filebyte);
                                        System.out.println("\nFile Name :"+filename);
                                        statusCheck.close();
                                        Path source = Paths.get(FilePath);
                                        Path destination = Paths.get("C://REST API//destination");
                                       System.out.println("Start to copy file to destination folder");
                                       Files.move(source, destination.resolve(source.getFileName()));
                                       System.out.println("Completed");
                                       fileStatus fs = new fileStatus();   //line 80
                                       fs.pass(filebyte, filename);
                                    }
                                    break;
                                }
                                catch(Exception e)
                                {
                                    System.out.println("In Copy Process" + e.getMessage());

                                }
                               }
                   }



这是 pass()方法的代码

private void pass(long filesize, String filename) 
    {
        {
             String dir = "C://REST API//destination//";
             String Finalfile = dir.concat(filename);
             System.out.println("file size :" +filesize);
             System.out.println("file name :" +filename);
             System.out.println("file dir :" +Finalfile);
              HttpClient client = new DefaultHttpClient();
                HttpPost post = new HttpPost("http://192.168.0.27:8008/file");  //remote API URL 
                FileBody bin = new FileBody(new File(Finalfile));  // take the file from directory 
            //    ArrayList ArrList = new ArrayList(1);
            //    ArrList.add(new BasicNameValuePair(bin));
                 HttpEntity reqEntity = MultipartEntityBuilder.create()  // build require argument 
                           .addPart("file",bin)
                           .build(); 
                post.addHeader("filename", Finalfile);  
                post.setEntity(reqEntity);  // send via post method 
                HttpResponse response = null;



从我的编译器中的错误消息,它显示第81和252行有 HttpEntity pass()方法参数的问题。谁知道我的错误是什么?我已经包含了httpmine 4.3.6 jar但它也没有工作

0 个答案:

没有答案