Take the 2-minute tour ×

I have problem with my program in JSF on Google App Engine platform. I almost finished implement chat application in Java EE, when I read that class FileOutputStream isn't supported by GAE. By this class object I create file, to write inside it chat messages and by scirpt this file is loaded and refreshed on index.xhtml website.

I need help because I don't know which class can I replace FileOutputStream to finish this application. I found example in Python so I know that this is possible, but how to implement it in Java?

I will be grateful for any help.

Below I paste piece of class ChatBean with FileOutputSream operations:

public class ChatBean {

    private List<String> users = new ArrayList<String>();
    private String newUser;
    FileOutputStream chatHtmlBufferWriter;

    public ChatBean () throws IOException {
        ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        String chatHtmlPath = ctx.getRealPath("/") + "chat";
        try {
            this.chatHtmlBufferWriter = new FileOutputStream(chatHtmlPath);  
            this.chatHtmlBufferWriter.write("Start chatu ąęć. <br />".getBytes("UTF-8"));
        } catch (IOException ex) {
            throw ex;


    public void closeFileBuffor() throws Exception {

    public String addMessage(String msg) throws IOException {
        return "index"; 

And script inside index.xhtml file:

                var currPos = 0;
                var loadChat = function() {
                    currPos = $(".chat")[0].scrollHeight;
                var scrollChat = function() {
                var currPos;

                $(document).ready(function() {
                    $("#chatForm\\:chatbox").load('chat', function(){
                    var refreshId = setInterval(function() {
                    }, 1000);
                    $.ajaxSetup({ cache: false });                    
                    $("#chatForm\\:chatbox").scroll(function() {
                        currPos = $(".chat").scrollTop();
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Basically, you can't directly write to the File System (although you can read).

You will need to use one of the existing GAE storage APIs, such as the blobstore which has a File like API. Other options are detailed on the Storing Data page.

However, I'm not sure you're thinking about this correctly; you just want to create a GET method that returns the current messages and is called by your script. The messages will never be written to file at all. To begin with, you could just store the messages in memory. I suspect the tutorial you link to does the same.

(UPDATE: I originally said FileOutputStream was in the whitelist, but I was looking at FilterOutputStream. Oops.)

share|improve this answer
Thanks for answer I'll check it. Now I started to think about another way of this problem. Maybe is possible to write messages to object and show it without use file? –  user1494328 Aug 26 '12 at 14:16
Yes, that's basically what I'm suggesting. Implement a GET method for the "/messages" URL or such which should return the list of current messages. You then make an AJAX call to this URL from the script and it should insert the messages into the page. –  Adrian Mouat Aug 26 '12 at 15:44
I'm not quite sure how it should look. Could you post sample structure of source code for this solution? –  user1494328 Aug 26 '12 at 20:50
Why don't you just look at the Python example and do something similar? –  Adrian Mouat Sep 2 '12 at 11:06
I did it and it works. –  user1494328 Sep 2 '12 at 11:47

Your Answer


