I’ve created my simple application.
When I list all files and directories from “.” dir I get it all from dir ‘web’. My goal is to create a new directory in ‘web’ called ‘myfile’. Unfortunately when I clicked a link on the page (which running the following code) it throws an exception…
Could you tell me how I can create file/dir in ‘web’?
And my 2nd question:
Assuming my app is bigger and used by several people. I want to create directories for all of them but it’s so uncomfortable to save all of this in my ‘web’ directory. Is it possible to create other server or take other place for ‘users’s files’?
Thanks!
package myapp;
import java.io.File;
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tools.ant.taskdefs.Mkdir;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
public class MyAppServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// getting logged user
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
// anybody is logged
if (user != null) {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, " + user.getNickname());
File test = new File(".");
String [] tab = test.list();
// list of files before
for (String el : tab) {
resp.setContentType("text/plain");
resp.getWriter().println("File ->, " + el);
}
File test2 = new File("./myfile");
test2.mkdir();
// list of files after
for (String el : tab) {
resp.setContentType("text/plain");
resp.getWriter().println("File ->, " + el);
}
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
}
GAE doesn’t have any file system. Read http://code.google.com/intl/en-US/appengine/docs/java/runtime.html#The_Sandbox:
Your only option is to use the datastore (and blobstore)