Android database creation - java

I am creating a android application where I need to create the database in which data comes from excel file on first run when the application starts.
The problem is where should I keep the file and how do I access it in my android application or there is another method to create the database from excel sheet.

Use assets folder of your application. It allows you to store files there and access them through AssetManager. It has open(String filename); method which returns you InputStream to a file from assets folder.

Related

upload file and auto down to local for access

I'm writing a portlet web app to allow user upload a excel file, and then the backend will do the validation to the excel file and convert the content into sql statement
The back-end is using java with library aspose.cells to handle the excel access.
The problem is, how can I pass the excel to back end to access.
Now I've think of after user upload the excel file, the back end first will download the excel file to local (maybe C:\temp), and then it can directly read the excel file from C:\temp rather than server file.
But it's possible to do it?
You seem to be looking for some sample code where you may upload an Excel file and then using Aspose.Cells for Java, process this uploaded file. You may have a look at the following link where a tutorial is there for uploading files using portlets.
http://www.codeyouneed.com/liferay-portlet-file-upload-tutorial/
Once the file is uploaded, use com.aspose.cells.Workbook class object for loading this stream directly into Workbook and then process it as per your requirement.
Following is the link to sample code for loading Excel file (in stream) into Workbook object:
https://docs.aspose.com/display/cellsjava/Opening+Files+with+Different+Formats#OpeningFileswithDifferentFormats-OpeningthroughStream
Note: I am working as Support developer/ Evangelist at Aspose.

Android Print Manager - return saved pdf file path

Using Android PrintManager API user can save content as PDF into device's internal/external directory.
I need to get that PDF file's path as soon as it is created. Is there any way to do this directly without having to use a file chooser?
Any ideas are appreciated.
Using Android PrintManager API we can save content as PDF into device's internal/external directory.
No. The user can elect to send your print job to a PDF file that is stored locally. The user could elect to do something else:
Send it to an actual printer
Send it to something else (e.g., Cloud Print)
Abandon the print job
Is there any way to do this directly without having to use a file chooser?
No, simply because there is no requirement for the user to save the content to a local PDF file in a place that you can access. In addition to all the above non-PDF alternatives, the user could save it as a PDF to removable storage, in a directory that your app cannot access.
I need to get that PDF file's path as soon as it is created
Then the PrintManager API is not suitable. Generate a PDF some other way (e.g., iText).

LibGDX: How can I access an xml file from core?

I've got an xml file I need to access(read only) from core. I tried putting it in the Android assets folder since that's shared, but ironically only the desktop version of my app can access it, the Android one doesn't see it at all. "Gdx.files.getLocalStoragePath" points to a different location on the Android version. Is there a spot I can store an xml file so I can access it via core?
create FileHandle object using your file.
FileHandle handle = Gdx.files.internal("data/myfile.xml");
parse that using XmlReader, that is in libgdx bundle.

How to insert a file into the project using Java

I am trying to figure out if it is possible to insert a file into the project using code.
I have a jsp. page which has a filechooser for the user to choose a file from, and the file is then saved into a database table as a byte[]. I also save the name of the file (in form thisIsAFile.png) into the same table.
What I want to know is if it is possible to insert the file into the project resources?
I have created a file into the project where I would like to save the file into using code.
I am aware that right clicking the project and doing an import is a way to add a file into the designated file manually, but I do not want that, instead I need a way for the file (in this case images only) to be saved into the project automatically, every time a user chooses a file to be saved into the database from the .jsp page. The path I am trying to insert the files into is gotten from a .properties file as /images/banners/{0} Then I only need a way to get the name (which contains the actual name + . + mime type of the file) from the database into the {0} and save it in the path as the byte[] from the corresponding row of the database.
Any help is much appreciated.
Save the file directly to the filesystem when it is received by the servlet. You can save other data about the file to DB but instead of saving the file to the DB create a FileOutStream and save it to a File
see http://www.mkyong.com/java/how-to-convert-array-of-bytes-into-file/
After than you can set the img src tag to the physical location of the file, or to a servlet which will return the response as a outputstream

Android - How to package documents into an app

I'm trying to create an app and have the ability to save files to /data/data/(packagename)/files or a directory similar to that. The goal would be to have a pdf or doc handler, as necessary, open the files stored on the internal storage and be viewed by the user. I have the code to get a pdf reader that is installed and display the file but I do not know how to package the files so they are installed in a directory like the one above. Also, if I am able to do this would I use getResources to access the files? How should the file structure look in eclipse to make this happen on install of the APK?
I do prefer to have the files stored internally (they are small) and not on the SD card.
I admit I am new to this and am trying to learn as I go. Thanks for the help!
As I understand your approach you only need to place your files to assets folder of your application and then just copy them to the internal storage. Read more here.

Categories

Resources