ssummeraw 2013-05-31 08:46 采纳率: 10%
浏览 2001
已采纳

android 开发中文件名错误

   Integer val = myReceipt.receiptId ;
            String fileName = "image" + "_" + title.getText().toString()+"_" + val.toString(); 
            photo = this.createTemporaryFile(fileName, ".jpg");
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
            uriOfPhoto = Uri.fromFile(photo);
            startActivityForResult(intent, RESULT_CAMERA_SELECT);
          }
        }


    private File createTemporaryFile(String part, String ext) throws Exception
    {
        File tempDir = new File (Environment.getExternalStorageDirectory() + "/Catch All Keeper/Receipts");
        if(!tempDir.exists())
        {
            tempDir.mkdir();
        }
        tempDir.canWrite();
        return File.createTempFile(part, ext, tempDir);
    }
});

我用上面的代码应该给出文件名image_title_val,但是却给出一个奇怪的名字image_title_(some random numbers).jpg。

为什么出现这个问题?

  • 写回答

2条回答

  • hxn_217 2013-06-03 03:12
    关注

    你使用 File.createTempFile 来获取一个唯一标识符,那个函数指定了随机数。
    传入参数部分的文件名字符串用做一个前缀来生成临时文件名称。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?