I have a file on an SD card that is a .txt file that my GUI needs to read the problem is that the GUI will be used on different computers and both on mac and windows OS. the .txt file is rather unique so wont be found on any other drive.
is there a way to scan every drive except C drive(to speed things up as i know it wont be there) to find the file so i can load it into my file reader?
thanks for any help?
You can use java.io.File.listRoots() to see the available drives.
You can use a recursive call through the entire file system: You can use the following methods of java.io.File:
listRoots() : list the root files (In Windows it's the drives, on Mac OS X and linux it's '/').
listFiles() : list the enclosing files of a directory
To recursively search for file check the following link
Search directories recursively for file in java
Related
I have three separate Linux servers that mount and share the same single file system under a directory called /efs
I have a Java application that uses this file system, and needs to be able to verify that the file system has been mounted correctly (Or else, it would simply write to /efs on the local machine instead of the shared storage without knowing) - How would I detect at run time from my application that the file system has been mounted to the directory?
Sorry if this is a duplicate question. I really did try to find information on this but I couldn't find a clear answer.
I see a few approaches to this problem:
If the mounted filesystem at /efs is different from the root filesystem, you can compare them using Files.getFileStore(path).type(). The filesystem for / being the same would then be a clear indicator that the /efs mount is missing. This assumes JDK >= 7.
Read and parse /proc/mounts to see which file systems are mounted and with which options. This is the same data source Java's FileStore API uses under the hood, so you might take the parsing logic directly from the JDK sources. This would be independent on the Java version.
Have a file on the mounted filesystem which is never on the root filesystem which can then be checked for simply by Files.exists(path) or new File(path).exists(). This would be independent from the Java version and even independent from Linux.
Answering my own question - It just occurred to me to create a file in the mounted file system and simply check the file exists avoiding any OS dependent code.
I would like to extract the images from an android game.
Firstly, I took the APK on my windows 10 laptop then I extracted the files (rename files.apk to files.apk.zip and extracted it with 7zip).
Inside my folders I got many .png files but I get an error when I try to open one. Each .png file has another file with the same name but with .png#. Some even have 2 otherfiles with them : one with .skel (can't open this one too) and .atlas (I can open it with notepad):
Did I make mistakes? What can I do to "repair" all these png files?
Thank you for you help!
If you are authorised to do so then you can apktool.
Its easy to use and may that #png files will be converted to some meaningful resource.
Installation for Apktool
Windows:
Download Windows wrapper script (Right click, Save Link As apktool.bat)
Download apktool-2 (find newest here)
Rename downloaded jar to apktool.jar
Move both files (apktool.jar & apktool.bat) to your Windows directory (Usually C://Windows)
If you do not have access to C://Windows, you may place the two files anywhere then add that directory to your Environment Variables System PATH variable.
Try running apktool via command prompt
Link
I created a simple file write/read app in Eclipse and have successfully tested that it could read what it wrote. The structure is fairly simple. I use FileOutputStream to write a samplefile.txt using openFileOutput and a FileInputStream using openFileInput to read it back. The only minor thing is that I don't know where is the file on my physical hard drive? Can anybody point me to where I could find the file in Windows?
If you dont give a absolute path the file will be creataed in aplication directory.
This is /data/data/packge-name-of-your-app/
e.g:
/data/data/com.example.test/
See more http://developer.android.com/training/basics/data-storage/files.html
Go to DDMS perspective, select the emulator which you are using, go to package explorer tag ,then you will get a list of folders hierarchy.
Go to /data/data/
Now you will see a list of packages installed, search for the package name of your app and expand it.
Here you will see the files which your application created when it was running.
P.S : You cannot find this file on the physical drive of your computer,because it is present in the storage of the emulated android virtual device. This storage cannot be directly accessed by you.
I am trying to write a log file from an applet.
When running as a Java application, I am able to write to the files,
but when running as an applet, I get .\logs\test.log (The system cannot find the path specified).
How do I permit it to write to disk, while debugging using eclipse?
EDIT: is it because of the backslashes?
You should write whatever you want from applet in temp file, to create temp file Try this
. Also you get system temp folder in java and create your file there, Read this. #Yoni is right you have limited permissions when you are in applet.
I am working on a small basic GUI program that gets the files from my resources and gets the names of the files and places them in a combo box. for example i just have a file inside the same package called images and trying to get the files names. the way I get the file is by using the getResoure() like so
java.net.URL url = FileDemo.class.getResource("images");
but when I try to get the files inside the directory
File urlfile = new File(url.toString());
String[] files = urlfile.list();
the first line will convert the url to string and create a file object but when I try to get the list of files inside the directory it returns a null to the array of strings.
I broke down the code and used the debugger in netbeans found out, when it did the SecurityManager check it wouldn't pass.
My question is are the files inside the project protected or there is no way to access them using the list() and listFiles() or am i doing something wrong? Also I ran the same script on my schools computer which they have windows 7 the code above worked. But when i ran it on my mac and even 2 win xp machines it just didn't work? why is that ?
I hope this makes sense i am just stuck here still a new to java
Thanks in Advance.
The class to getResource(String) is returning a URL to images but there's no guarantee that this is a file URL (beginning "file:"). If your class is embedded within a jar file this certainly won't be the case, hence why it fails in some situations and not others.
If your intention here is to actually make a portion of a file system visible to the user then I'd recommend avoiding getResource altogether, which is typically more useful when your application wishes to locate and load resources such as icons or config files.
Instead, you could use JFileChooser, which is a rich Swing component for navigating the file system and selecting files.