Sorry if this is a bit OT.  I have a file upload form that posts to the code below.  The code takes the uploaded file and writes it to the server.  The only problem is that it only works with text files.  It will write any file, but types like Word docs won't open.  I'm pretty sure the problem is that I'm using the FileReader/FileWriter classes, which only work for character files.  I think I should be using the InputStreamReader/InputStreamWriter classes, but I'm pretty clueless as to where to start. And just so I don't get accused of plagiarism, I modified this code from someones blog (I forget who though).

   <cfscript>
      s = "";
      cls = s.getClass();
      
      stringClass = cls.forName("java.lang.String");

      fileReaderClass = cls.forName("java.io.FileReader");
  fileWriterClass = cls.forName("java.io.FileWriter");
      
      a = arrayNew(1);
      a[1] = stringClass;
  
      b = arrayNew(1);
      b[1] = stringClass;

      fileReaderConst = fileReaderClass.getConstructor(a);
  fileWriterConst = fileWriterClass.getConstructor(b);
      
      a[1] = form.upFile;
  b[1] = form.path;

      fileReader = fileReaderConst.newInstance(a);
  fileWriter = fileWriterConst.newInstance(b);
      
      readerClass = cls.forName("java.io.Reader");
      a[1] = readerClass;

      bufferedReaderClass = cls.forName("java.io.BufferedReader");
      bufferedReaderConst = bufferedReaderClass.getConstructor(a);
      
      a[1] = fileReader;
      bufferedReader = bufferedReaderConst.newInstance(a);
  
      try {
          do {
              s = bufferedReader.readLine();
  fileWriter.write(s);
           } while (true);
       } catch (coldfusion.runtime.UndefinedVariableException e) {
          // this indicates end of file, ok to ignore error
       }

   fileWriter.close();
   </cfscript>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to