I am new in android programming and I am struggeling with saving an existent CSV file. I wrote the Code with Java in Processing. and it works on the PC but now I would like to switch to android Mode - but how can I Move the CSV file to my phone? and is there an easy way so i can use the Command:
table = loadTable("Vocstest.csv", "header");
I use Processing 3.37
The code you wrote will work just fine on an android phone. I have used the same code as yours in an app.
The difference may be that i do not try to override it (by saving) I am only accessing it to retrieve the data.
You have to add your file in the "data" directory in your project. If the "data" folder does not exist you can create it and put in your csv file.
example:
Table aQaK = loadTable("aQaK_ar.csv", "header");
TableRow myrow = aQaK.getRow(myversenum);
String myversetxt = myrow.getString("AyahText");
Hope this helps. Peace.
Related
I'm doing an internal Project, in Java, where i have to read an Excel and Parse it into a mpp respectively a MS Project compatible .xml file. I'm creating the file and everythings working fine.
But i want to show the columns "Work" and "ID" by default.
I can show them in MS Projects and the values are as I expect them to be, but i have to select and show them. Is there a possibility to show them by default when you open the .xml file?
I tried a lot and searched:
https://www.mpxj.org/
https://www.mpxj.org/apidocs/overview-summary.html
https://github.com/tmyroadctfig/mpxj/tree/master/net/sf/mpxj
adding columns to header in mpxj using ProjectWriter
as well as StackOverflow. But i didn't found any Information helping me out or it wasn't helpful cause methods changed and i didn't found the equivalent new ones.
this is where i fill the tasks and resources of my mpp.
if (!extractedRow.getElement().isEmpty())
{
element = contract.addTask();
element.setName(extractedRow.getElement());
element.setStart(startingDate);
element.setOutlineLevel(LookUp.Mpp_Conversion_Element_OutlineLevel());
element.setID(id++);
}
else if (!extractedRow.getWorkpackage().isEmpty())
{
workpackage = Objects.requireNonNull(element).addTask();
workpackage.setName(extractedRow.getWorkpackage());
workpackage.setOutlineLevel(LookUp.Mpp_Conversion_Workpackage_OutlineLevel());
workpackage.setID(id++);
}
else if (!extractedRow.getTask().isEmpty())
{
task = Objects.requireNonNull(workpackage).addTask();
task.setName(extractedRow.getTask());
task.setType(TaskType.FIXED_WORK);
task.setOutlineLevel(LookUp.Mpp_Conversion_Task_OutlineLevel());
task.setWork(Duration.getInstance(extractedRow.getEstimatedTime(), TimeUnit.HOURS));
task.setDuration(Duration.getInstance(extractedRow.getEstimatedTime() / 8, TimeUnit.DAYS));
task.setRemainingWork(Duration.getInstance(extractedRow.getEstimatedTime(), TimeUnit.HOURS));
task.setID(id++);
if (!extractedRow.getRole().isEmpty())
{
for (Resource resource : _project.getResources())
{
if (resource.getName().equals(_filereader.get_mapper().getMapping(extractedRow.getRole())))
{
assn = Objects.requireNonNull(task).addResourceAssignment(resource);
assn.setStart(task.getStart());
assn.setWork(Duration.getInstance(extractedRow.getEstimatedTime(), TimeUnit.HOURS));
}
}
}
}
Kind Regards
Unfortunately using an MPP file is the only way for you to specify the visual appearance of a schedule automatically when it is opened by Microsoft Project.
You have a few options:
I believe Aspose.Tasks can generate MPP files, so it may be that as part of that you can configure the layout you want
As you are already working with Excel you may want to consider using VBA which would allow you to both extract the data you need from Excel, populate the schedule in MS Project and configure the layout of the schedule.
Finally, if you want to use MPXJ, when you generate the MSPDI file and import it into Microsoft Project you are given some options about how the file is opened (as a new schedule, append to an existing schedule, update an existing schedule). If you create an empty "template" MPP file with the visual layout you require, using the append or update options when you open the XML file and selecting the template file as the target should give you a finished file using the data you've generated with the visual layout you need.
I have an image file
image = JavaSparkContext.binaryFiles("/path/to/image.jpg");
I would like to process then save the binary info using Spark to HDFSSomething like :
image.saveAsBinaryFile("hdfs://cluster:port/path/to/image.jpg")
Is this possible, not saying 'as simple', just possible to do this? if so how would you do this. Trying to keep a one to one if possible as in keeping the extension and type, so if I directly download using hdfs command line it would still be a viable image file.
Yes, it is possible. But you need some data serialization plugin, for example avro(https://github.com/databricks/spark-avro).
Assume image is presented as binary(byte[]) in your program, so the images can be a Dataset<byte[]>.
You can save it using
datasetOfImages.write()
.format("com.databricks.spark.avro")
.save("hdfs://cluster:port/path/to/images.avro");
images.avro would be a folder contains multiple partitions and each partition would be an avro file saving some images.
Edit:
it is also possible but not recommended to save the images as separated files. You can call foreach on the dataset and use HDFS api to save the image.
see below for a piece of code written in Scala. You should be able to translate it into Java.
import org.apache.hadoop.fs.{FileSystem, Path}
datasetOfImages.foreachPartition { images =>
val fs = FileSystem.get(sparkContext.hadoopConfiguration)
images.foreach { image =>
val out = fs.create(new Path("/path/to/this/image"))
out.write(image);
out.close();
}
}
I'm trying to make a chatbot using android studio but i can't find a way to connect it to the AIML files correctly here is the code i tried
String request = s;
String response = chatSession.multisentenceRespond(request);
while (response.contains("<")) response = response.replace("<","<");
while (response.contains(">")) response = response.replace(">",">");
if(response.equals("Too much recursion in AIML"))
return "";
else
return response;
I think by 'integrate' you mean that you want the bot to scan the AIML file and give a response according to the input provided by you.
For this, you have to follow following steps:
First put your AIML files in assets folder in Android Studio file hierarchy.
Then you have to save those files to your phone memory.
Then you have to use an interpreter like Program AB to get appropriate response according to the data you enter.
You can refer this link to get you started with it.
My objective is to write android sqlite database table into a csv file which can be read easily by human on a computer. I want to be able to open the csv file on my computer for viewing of data.
I have researched on stackoverflow about exporting database table to csv and one of code that i use is from Exporting SQLite Database to csv file in android. I have tried several other code on stackoverflow. All the other code suggested on stackoverflow is correct also but it cant seem to meet my objective.
Basically my code is similar to the link above.
My code can run without compilation error, meaning it can run without any error.
However, i faced a problem. Either the file was not created onto my computer for viewing or it is created in some android internal folder. I tried to search on window search button for ".csv". However i could not find the file that is supposed to be created. All i need is just a csv file with the database table data inside it.
I really appreciate if someone can guide me on what goes wrong or where i can locate the actual csv file.I am currently using an android phone. The following is my code that is of concern.
public void writeToCSV(){
for (int i=21; i<37; i++){// write each average table to a csv file
String tableNameString = "test" + i + "AveRssiTable";
String csvFilename =tableNameString+".csv";
File exportDir = new File(Environment.getExternalStorageDirectory(), "");
if (!exportDir.exists())
{
exportDir.mkdirs();
}
File file = new File(exportDir, csvFilename);
try
{
file.createNewFile();
CSVWriter csvWrite = new CSVWriter(new FileWriter(file));
SQLiteDatabase rssiDB = this.openOrCreateDatabase("rssivalue", MODE_PRIVATE, null);
Cursor curCSV = rssiDB.rawQuery("SELECT * FROM "+tableNameString,null);
csvWrite.writeNext(curCSV.getColumnNames());
while(curCSV.moveToNext())
{
//Which column you want to export
String arrStr[] ={curCSV.getString(0)};
csvWrite.writeNext(arrStr);
}
csvWrite.close();
curCSV.close();
rssiDB.close();
}
catch(Exception sqlEx)
{
Log.e("MainActivity", sqlEx.getMessage(), sqlEx);
}
}
}
If you are testing this code on emulator then your file is present in emulators SD card. You can access from Eclipse->DDMS->Devices(Select emulator)-File Explorer->storage->sdcard.
Click on the file then select a option of pull a file from device. save it then open it.
If you are testing your app on mobile then search it in your mobiles SD card.
If file is created successfully then you will find it in above locations. If file is not present in above location then there must be some error in your code
In my new app I wanted to make an IO object that will help me access text files written in a raw folder located in the res folder.
The object is a java class that is written in the same location as all of the rest java files.
The goal of this object is that I can access files from all of the activities instead of writing them again and again.
But when I tried to do that I stumbled upon a few errors that I can't find a way to fix them.
While writing the code:
FileOutputStream fos = new FileOutputStream(R.raw.fName);
(fName is a Sting that the action receives)
Android studio marked the "raw" red and said it didn't recognize it.
From what I understand the R file doesn't recognize the raw folder.
The second problem is , when I write the code:
InputStream is = Context.this.getResources().openRawResource(R.raw.fName);
It still gives me an error at the raw and an error at "Context.this" , and asks me to split the deceleration or to surround it with a try block , which doesn't help. And at the headline there is a throws IOException so any errors with IO should be cleared.
And if there is an easier way to access actions in java files , a link or an explanation will help a lot.
P.S. a raw folder is a premade folder with premade text files , also an easier way to read and write in premade files will help.