public OutputStream receiveUpload(String filename, String MIMEType) { mainTabs.setReadOnly(true); subTabs.setReadOnly(true); FileOutputStream fos = null; // Output stream to write to file = new File(filename); try { System.out.println(MIMEType); if (MIMEType.equalsIgnoreCase("text/plain") || MIMEType.equalsIgnoreCase( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") || MIMEType.equalsIgnoreCase("application/octet-stream")) { fos = new FileOutputStream(file); } else { } } catch (final java.io.FileNotFoundException e) { Label l = new Label("<h4 style='color:red'>" + e.getMessage() + "</h4>"); l.setContentMode(Label.CONTENT_XHTML); expDetails.addComponent(l); e.printStackTrace(); return null; } catch (final Exception e) { // Error while opening the file. Not reported here. e.printStackTrace(); return null; } return fos; // Return the output stream to write to }