Get file current local folder and search inside it - java

I'm in doubt about something. I'm developing a Java Desktop application and I have a problem.
I need to get the current local folder that my application (jar file) is in user system. And after this, to search inside of this same folder for some files (like all .txt file, for example). And finally, get the name of only one of this files and converts to string.
Someone can help me?
Antecipate thanks.

May be the getCanonicalPath() and getProperty() functions could help you, since you don't show any code I can't make you any example, but may be looking this could help you a little.
And also there is a similar question here

Related

how do i go about doing this file path?

I made an app that i'm am working on updates for and in the old version I hard coded the file path like this
"/data/data/my.app.here/troll"
so now I am trying to do an update and I am trying to use something similar to
Context.getFilesDir()
but that returns
/data/user/0/my.app.here/files
the app info is stored on the troll file and when I push updates I don't want to use another path and have them start their information all over again. What's the best way to resolve this situation?
Can someone kindly tell me the best way to resolve this situation?
Call getParentFile() on the File returned by getFilesDir() to get its parent directory. Your troll file should be in there. That wasn't a great place to put a file, and so YMMV.
If your concern is the /data/user/0/, that will be handled by Android and should map to /data/data/ when the primary user is the one running your app.

writing and reading input to xml

I am new to Android development and have been struggling with a problem. I have been trying to learn how to save user inputs to file. I have asked a similar answer and ended up figuring out a solution although it didn't work out the way I want. I have been searching high and low about how to write files to xml. I would to have a user be able to save, add, retreive, and be able to remove items from an XML file. I think the problem I am having as far as learning this is I'm not sure what the processes are call to properly look for a solution. This isn't for school work, I'm not looking for anyone to write up some code for me. What I am hoping for is proper terminology, maybe a link to some helpful information and such. I believe this process is called parsing, and you can add to XML through appending, not sure about much after this. Thank you in advance to anyone who can offer assistance.
To have the XML always available for the app you should put it in the "assets" folder. You should copy-paste the xml file to modify it, to ensure the file won't be corrupted afterwards.
First you have to copy the xml to the sdcard (preferably to a folder with your app name as folder name), you can use this to learn how to copy a file. After you have done that you can use the JDOM Parser to modify that xml file.
Put the xml after the modification back in the assets folder.

Change Hadoop HDFS name of file

I want to change the automatically saved filename of a HDFS block on a cluster. So when I upload a file to the HDFS and it'll divided into blocks, they get generated names with several numbers.
I searched the code but couldn't find it.
It should be somewhere in the java code, not a configuration file, right?
Can someone may tell me in which classes this creation or definition of the filename happens?
Thanks a lot!
edit:
Ok found it.
FSNameSystem.randBlockId.nextLong()
Ok found it.
FSNameSystem.randBlockId.nextLong()

opening file with java application automatically

I want to create my own file format for a particular kind of file. When someone downloads this file I want their system to know it should be opened with my application.
For example when I download a .doc file, my computer asks me whether I want to save the file or open it with Open Office. Similarly, If that .doc file is sitting on my desktop, and I double click it, it automatically opens with the correct application.
I believe this has to do with associating the file extension with the application in the context of the underlying OS.
Can any one point me to some good resources about how to do this in java?
Thanks.
Edit:
Sorry I want to clarify. Is there a way I can have my application associate the file type with itself when it is installed?
Edit:
found this...
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/jdic_assoc/
platform independent solution
This source shows how to make a file association in windows:
http://www.rgagnon.com/javadetails/java-0592.html
You will probably have to do it per installer that you make in each OS.
found this... http://java.sun.com/developer/technicalArticles/J2SE/Desktop/jdic_assoc/ platform independent solution

setContentsURL related issue

Hai,
I am using Java GWT. In this i want to load one html file.
htmlPane.setContentsURL("http://www.chellasoftapp.com/ATBrowser/images/disclaimer.html");
htmlPane.setContentsURL("images/disclaimer.html");
Which one be the faster? How is it works?
In images folder of WAR I placed that html file. Is it correct place? Or Where can i upload this?
Give suggestion for this issue.
Thanks in advance.
Regards,
Sathya.A
This solution:
htmlPane.setContentsURL("http://www.chellasoftapp.com/ATBrowser/images/disclaimer.html");
has quite big disadventage. It doesn't work in development on local machine.
I would use
htmlPane.setContentsURL(GWT.getModuleBaseURL() + "/images/disclaimer.html");
This one always works, doesn't matter if your application is at http://www.chellasoftapp.com/ATBrowser/ or at URL root: http://www.chellasoftapp.com/
Can you put .html file into images directory? Yes you can, and technically it is still valid, however, it is not readable and not obvious. I.e. it is hard to understand for other developers.

Categories