Hey Doug,
thanks for the great tutorial. I'm using the upload function to provide text
import capability - so don't need the actual text file after extracting the
content. I'm setting the upFile reference to null after proceeding. Is that
sufficient, to make sure that any files will be left? I appreciate any help
in advance.

Kon

That's my code:

  private UploadedFile upFile;
...
public String getContentFromTextFile() {
                try {
                        if (upFile.getName().endsWith(".txt")) {
 
                                InputStream inputStream = 
upFile.getInputStream();
                                InputStreamReader infile = new 
InputStreamReader(inputStream);
                                BufferedReader inbuf = new 
BufferedReader(infile);
                                StringBuilder stringBuilder = new 
StringBuilder();
 
                                String line;
                                while ((line = inbuf.readLine()) != null) {
                                        stringBuilder.append(line);
                                        stringBuilder.append('\n');
                                }
                                
                                
this.currentQuestion.setText(stringBuilder.toString());
 
                                return "forward";
                        } else {
                                FacesContext
                                                .getCurrentInstance()
                                                .addMessage(
                                                                null,
                                                                new 
FacesMessage(
                                                                                
"Make sure that the file is a text file with the extension
.txt"));
                                return "error";
                        }
 
                } catch (IOException ioe) {
                        FacesContext
                                        .getCurrentInstance()
                                        .addMessage(
                                                        null,
                                                        new FacesMessage(
                                                                        "Make 
sure that the file is a text file with the extension .txt"));
                        return "error";
                } finally {
                        this.upFile = null;
                }
        }

-- 
View this message in context: 
http://www.nabble.com/Tomahawk-1.1.3-inputFileUpload-solution-tp6449010p15037032.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to