如何解决java创建的文件没有写权限?

解决方案 »

  1.   

    File file = new File("./readonly.txt");
    System.out.println(file.createNewFile());
    file.setReadOnly();
    os = new FileOutputStream(file);
    os.write(" ssss".getBytes());//java.io.FileNotFoundException: .\readonly.txt (拒绝访问。)
      

  2.   

    系统是
    linux
    resin-ee-2.1.14
    j2sdk-1_4_2_02File fl=new File(x_base+"/test.txt");
    fl.createNewFile();
    后产生test.txt文件。该文件无法用DreamWeaver自带的ftp上传功能覆盖,也无法用FlashFXP的ftp上传覆盖。
    [R] STOR test.txt
    [R] 550 'test.txt': Permission denied
    [R] Transfer Failed!
    [R] PASV在ftp下试着在改写权限,失败
    [R] List Complete: 1 KB in 0.09 seconds (12.7 KB/s)
    [R] SITE CHMOD 777 test.txt
    [R] 550 'test.txt': Operation not permitted
    [R] PASV删除test.txt,成功
    [R] DELE test.txt
    [R] 250 Deleting file 'test.txt'
    [R] PASV上传test.txt,成功
    [R] STOR test.txt
    [R] 150 Starting ASCII transfer.
    [R] 226 Transfer done. 0 bytes transferred.
    Transferred: test.txt 0 bytes in 0.03 seconds (0.1 KB/s)
    [R] PASV改写权限,成功
    [R] SITE CHMOD 777 test.txt
    [R] 250 Changing mode on file test.txt to 777.
    [R] PASV
      

  3.   

    无法ftp,可是用java还是可以对文件操作的 File fl=new File(x_base+"/test.txt");
    out.print(fl.createNewFile());
    FileOutputStream fo=new FileOutputStream(fl);
    fo.write("test".getBytes());
    fo.close();
    fo=null;
    fl=null;操作成功