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

发布于 2024-11-25 16:54:08 字数 1297 浏览 2 评论 0原文

我正在开发一个 Android 应用程序,它使用 HTTP PUT 读取/写入无线设备。

有没有办法设置创建/修改日期&由 HTTP PUT 创建的文件的时间属性,因为目前文件创建良好,但没有属性(创建日期时间、修改日期时间)。

如果您需要一些代码片段,请告诉我。(不确定有什么帮助)

这可能是设备的后备,即设备负责将这些属性添加到文件中?

我尝试在网络上搜索,但这个问题很难用 1 行/几句话来解释:)

提前致谢。

编辑:只是为了澄清,我尝试写入的文件已经存在,因此 HTTP PUT 只是覆盖它。(简单文本文件)。所以我只是传递一个 BYTEARRAY 实体来写入这个文件。但不知何故,在这个过程中,文件属性丢失了。

编辑:以下是 uploadFile 代码片段。 私有无效uploadFile(字符串数据){

   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();
    }
}

I am developing an app for android that reads/write to a wireless device using 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.

Let me know if you need some code snippet.(not sure what will help)

Could this be a fallback of the device i.e. 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 :)

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). and So I just pass a BYTEARRAY entity to be written to this file. But somehow in this process, the file attributes are getting lost.

Edit: Following is the uploadFile code snippet.
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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲念泪 2024-12-02 16:54:08

file.setLastModified(long)< 有什么问题/代码>

一些旧报告称它不起作用,但似乎已修复。

我找不到有关设置创建日期的任何信息,因为创建日期应该在自动创建文件时设置。

What's wrong with 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文