printwriter

踩过Local Socket的一些坑--C与JAVA的内部通信

随声附和 提交于 2019-11-28 19:23:30
Android中的本地套接字(Local Socket),主要用于进程或者线程间的通信,实现的方式类似于socket,但其实是对Linux中Socket进行了封装,具体的内容可以随便搜一下,有很多相关的教程,这里主要记录下实现的过程中遇到的很多问题。 Java层实现Server: try { localServerSocket = new LocalServerSocket( SOCKET_NAME ); while ( true ) { Log. v ( "sysser" , "Java: wait socket connect" ); LocalSocket socket = localServerSocket .accept(); Log. v ( "sysser" , "Java: socket connect success" ); while ( true ) { bufferedReader = new BufferedReader( new InputStreamReader(socket.getInputStream())); bufferedReader .read( recv_bytes , 0 , 1024 ); Log. v ( "sysser" , "Java: socket recv : " +String. format ( "%c" , recv

ireport后台传参打印pdf

笑着哭i 提交于 2019-11-28 17:50:20
第一;先说传参方式,一共有两种 JasperRunManager.runReportToPdfStream(is, servletOutputStream, map, data2); //1; 上面参数中的map,对应pdf中的Parmeter参数 //2; datasouce,参数中的第四位,对应pdf中的参数2,fields //map在官方解释中类似于sql的查询条件,DataSource就是具体的查询结果数据 第二;具体的数据参数形式 map,就是普通的hashmap就可以 //1;map,就是普通的hashmap就可以 HashMap map = new HashMap(); //传参对应方式 map(“”,XXX) //XXX可以是数据库,也可以是list,也可以是单个数据 //数据库 //要传入datasouce类型,获取的时候可以使用 使用方式 在ireport 组件list中使用 $P{REPORT_PARAMETERS_MAP}.get("XXX")直接获取 //表达式填入,图四 list //传入list,便利循环的时候要使用datasouce对应的格式转换 //要创建一个list field,然后更改这个field属性,图三我选择的是第一个 使用方式一 在ireport 组件list中使用,由于创建list时,就会自动附带subDataSource

流、文件与正则表达式

南楼画角 提交于 2019-11-28 15:30:54
第1次实验 0. 字节流与二进制文件 使用DataOutputStream与FileOutputStream将Student对象写入二进制文件student.data 二进制文件与文本文件的区别 try...catch...finally注意事项 使用try..with...resouces关闭资源 使用DataInputStream与FileInputStream从student.data中读取学生信息并组装成对象 我的代码 我的总结 1.二进制文件与文本文件的区别 二进制文件可以存储类似int/double/char的基本数据类型,但是文本文件只能存储char型变量,所以文本文件在读取或存储过程中常需要用到类型转换,例如将char型的转换成int的parseInt 2.try...catch...finally注意事项 catch多个异常时要注意异常写的先后顺序,越大的异常要放越后面 3.使用try..with...resouces关闭资源 可以直接在try(........)的括号中定义最后要关闭的资源,在运行结束后会自动关闭,不需要在finally中关闭资源 1. 字符流与文本文件:使用 PrintWriter(写),BufferedReader(读) 任务: 使用BufferedReader从编码为UTF-8的文本文件中读出学生信息,并组装成对象然后输出。 中文乱码问题

how to write to csv with a leading zero?

懵懂的女人 提交于 2019-11-28 10:44:32
问题 I wish to write to a CSV file some data. One of the column that I input the information is in the form of an integer with leading zeros, example: 0000000013. For some reason, excel 'converts' it to 13, and I must have it with 10 digits (0000000013). Can anyone tell how this can be circumvented? String value = "0000000013"; //I tried String.format("%8d", 13) doesn't work printWriter.println(value); Thanks!!! 回答1: Add a single quote, ' , at the start of the line. This informs Excel to not treat

HTTP_request_案例2_服务器输出字符数据到浏览器

吃可爱长大的小学妹 提交于 2019-11-28 10:27:44
字符数据 步骤: 1. 获取字符输出流 2. 输出数据 演示步骤: package zr.web.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; @WebServlet("/responseDemo3") public class ResponseDemo3 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1. 获取字符输出流 PrintWriter pw=response.getWriter(); //2. 输出数据 pw.write("<h1

What exactly is the use of flush for a printwriter object?

自作多情 提交于 2019-11-28 08:19:20
问题 I'm looking for a theoretical analysis. I mean, how does the buffer system works and what advantage does using flush provide? Kindly illustrate with an example, if possible. 回答1: When you are writing to a text file, BufferedWriter does not write it to disk immediately. Instead, it keeps the data in a buffer in memory. This has the advantage that many small writes will go into the buffer, and then the data will be written to disk in one go, ie. with one big write, instead of many small writes,

PrintWriter to append data if file exist

大兔子大兔子 提交于 2019-11-28 05:47:09
问题 I have a savegame file called mysave.sav and I want to add data to this file if the file already exists. If the file doesn't exists, I want to create the file and then add the data. Adding data works fine. But appending data overwrites existing data. I followed the instructions of axtavt here (PrintWriter append method not appending). String savestr = "mysave.sav"; File f = new File(savestr); PrintWriter out = new PrintWriter(savestr); if ( f.exists() && !f.isDirectory() ) { out = new

Is PrintWriter buffered?

喜欢而已 提交于 2019-11-28 00:45:53
问题 I know that the PrintWriter is really good if we want to write formatted data, and I also know the use of BufferedWriter to improve IO performance. But I tried something like this, PrintWriter pw = new PrintWriter(System.out); pw.println("Statement 1"); pw.println("Statement 2"); //pw.flush(); I observed that when the flush method is commented there is no output, but when I uncomment it, I get the desired output. This is only possible if the PrintWriter is buffered. If so, then what is the

How do you set a timeout on BufferedReader and PrintWriter in Java 1.4?

橙三吉。 提交于 2019-11-28 00:45:45
How does one set a timeout on a BufferedReader and a PrintWriter created using a socket connection? Here is the code I have for the server right now, which works until either the server or the client crashes: while(isReceiving){ str = null; BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter pw = new PrintWriter(socket.getOutputStream(), true); while ((str = br.readLine()) != null){ System.out.println("Processing command " + str); pw.println(client.message(str)); } } Outside the scope of this code I have imposed a socket timeout of 1000ms, which

What is the exact difference between out.write() and out.print()

冷暖自知 提交于 2019-11-27 20:14:22
In my servlet I gave both out.print and out.write . but both prints in the browser. What is the exact difference between these two and when to use out.print and out.write ? The basic difference is that out.write() explodes if you pass it a null: String s = null; out.print(s); // outputs the text "null" out.write(s); // NullPointerException PrintWriter : public void write(String s) Write a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions. print method has higher level of abstraction. public void print(String s) Print a string. If the argument