I have a url like this
https://example.com%3A443:443/www/36d8e8c94aae45048ba9f92f8e62c7b2/file/content?path=%2Fmnt%2Fsdcard%2Fvideo%2Fsample_mpeg4.mp4&yyy=9a7491a1f5664336b5c6bf431f42852c3749ed54722736ec748746858a710c44
I need to get the path of file as /mnt/sdcard/video from the URL . How do i do that ?
I used URL decoder to remove the spaces but i am confused on getting the path of the file .
Thanks for all your help.
Use Uri.getQueryParameter().
import android.net.Uri;
Uri uri = Uri.parse("https://example.com%3A443:443/www/36d8e8c94aae45048ba9f92f8e62c7b2/file/content?path=%2Fmnt%2Fsdcard%2Fvideo%2Fsample_mpeg4.mp4&yyy=9a7491a1f5664336b5c6bf431f42852c3749ed54722736ec748746858a710c44");
String pathParam = uri.getQueryParameter("path");
You can do it with the Uri class. Construct a Uri object and use Uri.getQueryParameter().
Related
I need a solution to convert file path to EMF URI, not a Java URI.
I tried with this:
org.eclipse.emf.common.util.URI ur = org.eclipse.emf.common.util.URI.createURI(URI.createURI(file.getPath()).toString());
...but I get this exception:
java.net.MalformedURLException: unknown protocol: c appears .
Is there another solution?
In EMF, URI classe comes with a lot of static methods to help you create your URI. In your specific case, try URI.createFileURI(...) instead of URI.createURI(...)
URI fileURI = URI.createFileURI(file.getAbsolutePath());
Look here for details about the method: http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.3/org/eclipse/emf/common/util/URI.html#createFileURI(java.lang.String)
I am trying to read a file using URL in java.
FileHelper.read(new File(getClass.getResource("TextFile.rtf")))
I am really confused with the below exception
error: overloaded method constructor File with alternatives:
(java.net.URI)java.io.File <and>
(java.lang.String)java.io.File
cannot be applied to (java.net.URL)
Any idea or suggestion how can I resolve this exception.
Thanks !!!
Try converting the URL to its URI equivalent:
FileHelper.read(new File(getClass.getResource("TextFile.rtf").toURI()))
See URL.toURI() for more information.
All you need to do is to get URI from the URL.
URL url = getClass.getResource("TextFile.rtf");
URI uri = url.toURI();
FileHelper.read(new File(uri))
I've got a string:
public://imageifarm/3600.jpg
How can I extract the
imageifarm/3600.jpg
Part out using android?
What I've tried so far:
URL drupalQuestionNodeImageURI = new URL("public://imageifarm/3600.jpg");
Log.d("TAG", drupalQuestionNodeImageURI.getPath());
but it throws this exception:
09-16 17:24:39.992: W/System.err(3763): java.net.MalformedURLException: Unknown protocol: public
How can I solve this?
I know I can use regular expressions but that seems to defeat the purpose of URL(URI) in this case.
You should use android.net.Uri
Uri mUri = Uri.parse(public://imageifarm/3600.jpg);
String extract = mUri.getEncodedSchemeSpecificPart();
Use java.net.URI, not java.net.URL.
If you want have to use URL class (when you image sits on Internet) you have to provide valid URL (that begins from valid URL prefix, like http://, https:// etc). In you case you should use Uri class. Uri object can point on files in your local file system. For example:
Uri.fromFile(new File("public://imageifarm/3600.jpg"));
I need a regex pattern that will find and replace brackets in urls to its urls encoding.
For example a base url like:
http://www.mysite.com/bla/blabla/abc[1].txt
will be turned to:
http://www.mysite.com/bla/blabla/abc%5B1%5D.txt
can anyone help please?
EDIT1:
i originaly use commons-httpclient to access this kind of urls.
when I use the first URL I get an "escaped absolute path no valid" exception.
I can't use URLENCODER because when I use it, I get a "host parameter is null" exception.
The following line should do the trick
String s = URLEncoder.encode("http://www.mysite.com/bla/blabla/abc[1].txt", "UTF-8");
Have you tried URLEncoder.encode?
in the java.net.URLEncoder package.
EDIT:
Ok i see... you cannot pass an entire URL to URLEncoder. URLEncoder is mostly used to encode query parameters.
try this instead:
URI uri = new URI("http", "www.mysite.com", "/bla/blabla/abc[1].txt",null);
System.out.println(uri.toASCIIString());
I am trying to replace url with another url.
Below is the example of source url
http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries/
so this url should be replace with below url,
http://sysserver01.internal.com/var/www/html/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries/
It means if source url comes then the part after resources in source url must be appended with /var/www/html/(and rest of part after resources in source url).
This needs to be happen with rendom set of source url that contains resources string.
I dont have enough knowldege of string manipulation. So please someone help me to solve this query. Please try to solve it in JAVA as I choose this platform for my work.
String originalUrl = "http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries";
String newUrl = originalUrl.replaceAll("web/www/internal/projectwork/resources", "var/www/html");
String originalUrl = "http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries";
String newUrl = originalUrl.replace("web/www/internal/projectwork/resources", "var/www/html");