I have a text file on a server, now if the user presses a button, the text file should get a new line .
My idea was to create a text file on the device...to read the actual text file of the server...to append 'this new line' and upload it to the server, but this way isn't safe, are there other ways to do this ?
Thanks in advance !!
if the server is a Web Server, you can simply send an Http request (Using HttpUrlConnection for example) from your application to a specific PHP file on the server, and put in this file (PHP file) the code to append a new line to the file or event to append a custom text content which you send it with the request.
No need to read the existing text from the server unless you need them on the device, if you you need is to add a new line of text, you just need to send the text from the device to the server and and append the text to the text file on the server.
Related
Happy new year everyone :)
I'm new user of Talend studio, this is the second time I'm using ESB conductor and I think I'm doing something wrong here.
So, at the beginning I received a file from a SFTP then I depose it to another SFTP.
There is no problem here.
Second, after send this file, I need to create a second file, take the name of the first one send, rename it and depose it to the destination SFTP.
My Route
So with the first component (cProcessor), I'm setting 2 variables :
exchange.setProperty("target_directory", targetDirectory);
exchange.setProperty("x_filename_trg", trgFileName);
Here, I retrieve the right filename (xxx.trg) and the right targetDirectory.
Now I'm using a cTalendJob to call a job who can create an empty file :
Inside cTalendJob
To recover the variables of my routes, in my cTalendJob I checked "use context of the route"
In my tRouteInput I setted the schema like this cRouteInput
Then I tried to create the new file on the folder :
Create new file
At the moment my problem is : My variable are not transmitted to my cTalendJob. How can I transmit and use them properly ? File Directory + FileName
Can I send this file to the SFTP on the cTalendJob or need I to send it from my route ?
Thank you if you read me and if you can help me :)
Did you try by using a cSetHeader instead of cProcessor, to pass the variable as headers and not as properties ?
Let me know if you need anymore details as I do not know what I should put to get some help.
So I have a password protected excel file that I send as an email attachment in my code. I password protect the file in the code. The file that gets saved locally asks for the password when I open the file. But when I open the file through the email I sent out it does not ask for a password and just opens right up. I searched online but couldn't find anything.
This is the code where I encript the file and send the email
HSSFWorkbook workbook = new HSSFWorkbook(poi,true);
workbook.writeProtectWorkbook("pass","");
FileOutputStream fo = new FileOutputStream(myExcelFile);
...
Email email = new Email(to, from , subject, body.toString(), true);
email.attachFile(myExcelFile);
email.send();
So after more testing and asking some coworkers I have found out that email programs don't know how to handle a file that has a simple password on it so it just opens up the file like normal. If you download the attachment and open it up through your file system then it will prompt you for the password, but if you just try to open it directly from the email itself (Outlook, Gmail, etc.) will just ignore the password and open it up.
What I've decided to do is just put the file into a zip archive and just add a password to that. Hopefully the email programs/apps don't ignore it or at least when you try to open the file from the archive it will prompt you for the password because you are no longer opening it from the email itself.
Long story short its the email programs/apps that is causing my problem not my actual code.
After having a similar issue (but using c# to compile and email the Excel file) I protected the worksheet before saving the file instead of protecting the workbook.
When opening the file from an email (or any other way) and attempting to edit a cell a warning is displayed that the sheet is protected and read-only until it is unprotected with the password.
Basically I've uploaded a text file to my host and I want to edit the file and read it with java. I've created the permissions for it but im not sure how to do it with Java. This is my code which read/writes locally:
Read:
BufferedReader mainChat = new BufferedReader(new FileReader("./messages/messages.txt"));
String str;
while ((str = mainChat.readLine()) != null)
{
System.out.println(decrypt.Decrypt(str, salt));
}
mainChat.close();
Write:
FileWriter chatBuffer = new FileWriter("./messages/messages.txt",true);
BufferedWriter mainChat = new BufferedWriter(chatBuffer);
mainChat.write(message);
mainChat.newLine();
mainChat.flush();
mainChat.close();
How would I have to modify this to make it work? Thanks
I don't think you can read/write directly to a file on a web server the way you would on a local filesystem. What you'll probably need to do is:
download the file
open it in the local editor
when it's saved, automatically re-upload the file
You can do this all within the editor, and hide this in the app by having it do the download-edit-save-upload in the background. Many text editors will do this by establishing a remote connection similarly, and making the file writing round trip transparent to user.
You should implement some sort of remote procedure call. Basically, from the client send the server a message containing what you'd like to put in the file. Then have the server actually open the file and write the content of the message to the file.
I have a scheduled task running in JBoss 5.1 on a daily basis for sending birthday wishes.
The mail content is HTML and I embed images in the mail.
Now I would like to get the path of that image for embedding, how would it be possible to get path of image in a non-servelt environment.
Ofcourse I could have placed the images at a static location and accessed them, for which I don't want to hardcode the path.
The image is at "WebContent/images/birthday.jpg" location.
How are you generating the email content? Are these also static html files?
If you are going to use simple static html files, you will have to hard code the image paths. There is no other way around it.
You could write a simple Java application, which runs as a standalone application (without any servers,servlets etc), which will create the email content.
The java code can send out the emails for you too if you want.
These are some of the things you can do, if you use java
Use property files to specify the location of images. These are files which hold simple key/value pairs.
You can easily create multiple email content to different users, with the same template.
You will be able to easily redesign the html content for multiple users.
An example of using property files.
Create a file ex: "email_template.properties"
Enter the following into the file and save it.
image_server=http://www.mywebsite.com
image_folder=/WebContent/images/
Create a jave program to create your html email, and use the property file to generate the image locations.
Properties properties = new Properties();
try
{
properties.load(new FileInputStream("C://email_template.properties")); //specify path here
String sServerLocation = properties.getProperty("image_server");
String sImageFolder = properties.getProperty("image_folder");
StringBuilder strEmail = new StringBuilder();
strEmail.append("<html><body> <img src=\"" + sServerLocation + sImageFolder +"birthday.jsp\""> </body> </html>" );
// Write code to generate complete email dynamically
// write code to send out the email or to save as html file to you machine, where you can send it manually.
} catch (IOException e)
{
//
}
You get the idea. using plain html you will have to hard code.
However if you use a simple java file you can get more flexibility.
If you need code to send out email from java, check this link out.
How can I send an email by Java application using GMail, Yahoo, or Hotmail?
To show the printable document directly with out saving that file, I set the response header as "Content-Disposition","inline". Now it is showing the file but some times that file not being opened. It is showing some error messages like
"There was an error in opening this document. The file is damaged and can not be repaired"
"Adobe Reader cannot open this file. It might not be supported file type or that file was damaged".
and If click on print button again it working fine It is showing the document. So what I have to do to avoid those error messages. Can you please suggest me.
Thanks,
Vara Kumar
Check how you build your stream of bytes on server. Those errors indicates truncated stream (=incomplete pdf) or extra data before or after the end of right content (=invalid pdf).