简体   繁体   English

在 java/Android 中使用 HTTP PUT 创建文件时没有文件创建/修改日期

[英]No file creation/modified date when a file created using HTTP PUT in java/Android

I am developing an app for android that reads/write to a wireless device using HTTP PUT.我正在为 android 开发一个应用程序,该应用程序使用 HTTP PUT 读取/写入无线设备。

Is there a way to set the creation/modified date & time attribute of a file being created by HTTP PUT because at the moment the file is created fine but with no attributes (creation datetime, modified datetime.有没有办法设置由 HTTP PUT 创建的文件的创建/修改日期和时间属性,因为目前文件创建良好但没有属性(创建日期时间,修改日期时间。

Let me know if you need some code snippet.(not sure what will help)如果您需要一些代码片段,请告诉我。(不确定有什么帮助)

Could this be a fallback of the device ie the device is responsible for adding these attributes to a file?这可能是设备的后备,即设备负责将这些属性添加到文件中吗?

I have tried searching the net but this problem is hard to explain in 1 line/few words:)我试过在网上搜索,但这个问题很难用 1 行/几句话来解释:)

Thanks in advance.提前致谢。

Edit: Just to clarify, the file that I am trying to write already exists so HTTP PUT is simply overriding it.(simple text file).编辑:为了澄清,我试图写的文件已经存在,所以 HTTP PUT 只是覆盖它。(简单的文本文件)。 and So I just pass a BYTEARRAY entity to be written to this file.所以我只是传递一个 BYTEARRAY 实体来写入这个文件。 But somehow in this process, the file attributes are getting lost.但不知何故,在这个过程中,文件属性正在丢失。

Edit: Following is the uploadFile code snippet.编辑:以下是 uploadFile 代码片段。 private void uploadFile(String data){私人无效上传文件(字符串数据){

   try{
          HttpClient http = new DefaultHttpClient(); //declare and initialize the HTTP client.
          //Using HTTP PUT, upload the data to the Settings file
          HttpPut putmethod = new HttpPut("http://airstash.net/files/SETTINGS.TXT"); 
          putmethod.setEntity(new ByteArrayEntity(data.getBytes("iso-8859-1")));
          putmethod.setHeader("Content_Type", "Text/Plain");
          HttpResponse response = http.execute(putmethod); //Execute the PUT request and receive response.
          if(response!= null)
          {
   //Show the response code (for testing only)
        String responsecode = Integer.toString(response.getStatusLine().getStatusCode());
        Toast.makeText(getApplicationContext(), responsecode, Toast.LENGTH_LONG).show();
    }
   }
    catch(Exception e){
        e.printStackTrace();
    }
}

What's wrong with file.setLastModified(long) ? file.setLastModified(long)有什么问题?

Some old reports that it doesn't work but appears to be fixed.一些旧报告称它不起作用但似乎已修复。

I can't find any information on setting the creation date because the creation date should be set when the file was created automatically.我找不到有关设置创建日期的任何信息,因为创建日期应在自动创建文件时设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM