I am trying to write some data to txt file using PrintStream.println. Some times it is working fine, But some times it is crashing the application. When i saw the result file, It contains <0x00> very huge amount of time. After that nothing printed in file.
Please find the below used code.
SimpleDateFormat sdf = new SimpleDateFormat("[MM/dd HH:mm:ss:SSS] ")
Date date_value = new Date();
String currentDateandTime = sdf.format(date_value);
FileOutputStream fileOutputStream = new FileOutputStream("fileName", true);
PrintStream plt_cbl_stream = new PrintStream(fileOutputStream);
plt_cbl_stream.println(currentDateandTime);
plt_cbl_stream.flush();
Can some one suggest me, What is the issue. Please find the details captured from created file.
Log captured from created file :
[20/01 15:30:24:865]
[20/01 15:30:24:8<0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00>68]
[20/01 15:30:24:872]
[20/01 15:30:24:877]
[20/01 15:30:24:892]
<0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00><0x00>
Related
Placed the reports have overrided all the resultsi would like to print in a table with results but when i printed it overriding the results and it is printing only one line
am passing the values form other class file to print the results
i have tried using Buffered writer for writing the code
public void createTestSummaryHTMLTable(String sample,String samp[le,String sample,String passedText,String status) throws IOException {
File file=new File("C:\\AutomationResults\\Forms\\",foldername);
if(!file.exists()){
file.mkdir();}
final String FILE_PATH =(file+"/"+formname);
//final String FILE_PATH = "C:\\AutomationResults\\Forms\\"+formname;
final String FILE_EXTENSION = "html";
DateFormat df = new SimpleDateFormat("yyyyMMdd"); // add S if you need milliseconds
String filename = FILE_PATH + "_"+ df.format(new Date()) + "." + FILE_EXTENSION;
File file2 = new File(filename);
// if file doesnt exists, then create it
if (!file2.exists()) {
file2.createNewFile();
}
BufferedWriter html = new BufferedWriter(new FileWriter(file2));
html.write("<html><body bgcolor='#E6E6FA'><table border=1 cellpadding=0>");
html.write("<title>Automation Summary report </title>");
html.write("<br>");
html.write("<center><strong><em>Batch report heading</em></strong>");
html.write("<span style ='float; right;position:relative;right:30px;font weight:bold'>"+new Date().toString()+"</span>");
html.write("<tr>");
addlabel1(html,"Test Step Name");
addlabel1(html,"Test Step Description");
addlabel1(html,"Status");
addlabel1(html,"Screenshot");
html.write("</tr>");
html.write("<tr>");
html.newLine();
addlabel(html,sample);
addlabel(html,sample);
String status1 = "Passed";
if (status1.equals(status))
{
html.write("<td width='20'style='color:#00F00;font-weight:bold;text-align:center'>"+status+"</td>");
} else {
html.write("<td width='20'style='color:#A52A2A;font-weight:bold;text-align:center'>"+status+"</td>");
}
addlabel(html,"Screenshot");
html.write("</tr>");
html.write("</table></body></html>");
html.close();
}
Oh, I think i guessed your problem. The file written is a single long line.
That is because write only writes what you give it. You need to put a \n at the end of all your strings.
Alternatively, use Printwriter's println method to output to your file.
You can try adding a boolean parameter to FileWriter that helps to specify whether it should append to or override the existing content. If you pass true, it would open the file for writing in append mode.
Please change this line:
BufferedWriter html = new BufferedWriter(new FileWriter(file2));
To this:
BufferedWriter html = new BufferedWriter(new FileWriter(file2, true));
the actualresult
header is displaying for every row i dont need the header to display for all the rows result am getting is
expected result is
header should display only once
I have just starting to use the Sat4j libraries. Can you direct me how to calculate the time taken to parse and simplify a given CNF input.
i have used
ISolver solver = SolverFactory.newDefault();
Reader reader = new DimacsReader(solver);
IProblem problem = reader.parseInstance(filename.cnf);
boolean check=problem.isSatisfiable();
i wish to calculate the time taken by the reader to parse and isSatisfiable.
if possible kindly direct me to find the information in the image for every cnf file processed
screenshot of the details i look to collect using sat4j lib
Thank you for your time in advance.
I try to embedded your source code in an old fashion way to get the execution time.
Date startDate = Calendar.getInstance().getTime();
long d_StartTime = new Date().getTime();
ISolver solver = SolverFactory.newDefault();
Reader reader = new DimacsReader(solver);
IProblem problem = reader.parseInstance(filename.cnf);
Date endDate = Calendar.getInstance().getTime();
long d_endTime = new Date().getTime();
System.out.format("Milli = %s, ( D_Start : %s, D_End : %s ) \n", (d_endTime - d_StartTime),d_StartTime, d_endTime);
boolean check=problem.isSatisfiable();
With this, the time in milliseconds to parse the instance will appear :).
I hope this help !
I have a servlet witch is generating a .xls file and then it's sending the generated file to the user for download with the code below:
// Write the output to a file
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter=
new SimpleDateFormat("yyyy_MMM_dd");
String dateNow = formatter.format(currentDate.getTime());
String path = "webapps/myapp/exports/";
String fileName = ("Table_export_"+ dateNow + ".xls");
FileOutputStream fileOut = new FileOutputStream(path+fileName);
wb.write(fileOut);
fileOut.close();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename="+fileName);
The file is saved on the server with a size of 5 kb, but after the browser dialog and after choosing save or open, the file is empty and the size is 0 kb. I can not understand what is wrong.
I'm fighting with this issue for about 2 hours without a success. I have tried to set the full path:
response.setHeader("Content-Disposition","attachment;filename="path+fileName);
But I got a document with a strange name and it also was 0 kb.
I'm pretty sure that I'm missing something really small, but as a junior developer I still can not figure it out.
Since you already have a method that can write your file to an output stream you can simply change your code this way to send it to the user :
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MMM_dd");
String dateNow = formatter.format(currentDate.getTime());
String fileName = ("Table_export_"+ dateNow + ".xls");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename="+fileName);
OutputStream outputStream = response.getOutputStream();
try {
wb.write(outputStream);
} finally {
outputStream.close();
}
It won't be saved on your server HDD though.
The method HttpServletResponse#getOutputStream() allows you to access the stream of bytes that will be sent back to the client.
When you used the format -
String path = "webapps/myapp/exports/";
String fileName = ("Table_export_"+ dateNow + ".xls");
...
response.setHeader("Content-Disposition","attachment;filename="path+fileName);
Was the filename "webapps%2Fmyapps%2Fexports%2fTable_export_....xls"?
Als the filesize would have been zero because you are not putting any data in the file
I am searching a way I want to test login and it is not possible to write all the function with hard code values So like we have Data driven(parametrization) in QTP etc the tool fetch data from a file and keep entering and at last all our inputs are executed ..
Is it possible to do via Roboitum ?
Please let me know for the same.
yes u can make a data excel file and u can fetch data from excel file
u can use
File storage = Environment.getExternalStorageDirectory();
String filename = "test.xls";
File myfile = new File(storage, filename);
FileInputStream fis = new FileInputStream(myfile);
Workbook ws = null;
ws = Workbook.getWorkbook(fis);
Sheet Wsheet = ws.getSheet(SheetNum);
String returnValue ;
returnValue = Wsheet.getCell(ColmnNum, RowNum).getContents();
same as how we use Excel reading in QTP , It works for me
I am using this code to save the data in the file. The data that is being saved in the file is ????????. Please help me with suitable solution.
File gpxfile = new File(activate, "activate.csv");
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(gpxfile),"UTF-8");
writer.write(merchantId);
It works for me. Make sure merchantId contains valid Hindi. For instance:
String str = "मानक हिन्दी";
writer.write(str);