如何通过替换 Android 中的文件存储路径来使用 URL

How to Use URL by replacing File Storage path in Android

我正在使用 Google 云打印从我的 phone 存储中打印 Pdf。我想通过替换它来使用 pdf URL。如何使用URL? 例如:我想将 /print/test.pdf" 替换为 "www.example.com/print/test.pdf"

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/print/test.pdf");
       Intent printIntent = new Intent(MainActivity.this,PrintDialogActivity.class);
       printIntent.setDataAndType(Uri.fromFile(file),"application/pdf");
       printIntent.putExtra("title", "Android print demo");
         startActivity(printIntent);

下载 http://central.maven.org/maven2/commons-io/commons-io/2.4/commons-io-2.4.jar 并将其粘贴到 Android Studio 中的 libs 文件夹中。打开你的 Gradle 文件并在依赖项中添加这个“compile files('libs/commons-io-1.3.2.jar')

                URL url = null;
                try {
                    url = new URL("http://www.cbu.edu.zm/downloads/pdf-sample.pdf");
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                String tDir = System.getProperty("java.io.tmpdir");
                String path = tDir + "tmp" + ".pdf";
                File file = new File(path); file.deleteOnExit();

                try {
                    FileUtils.copyURLToFile(url, file);
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Intent printIntent = new Intent(MainActivity.this,
                        PrintDialogActivity.class);
                printIntent.setDataAndType(Uri.fromFile(file),
                        "application/pdf");
                printIntent.putExtra("title", "Android print demo");
                startActivity(printIntent);