天道酬勤,学无止境

dataoutputstream

从 php 页面中的 java DataOutputStream 接收输出(receive output from java DataOutputStream in a php page)

问题 我有一个 java 小程序,我用它来将文件发送回我的服务器 - 在服务器端我想在 php 页面上接收它。 下面是执行发送的 java 代码,在 php 方面,我检查了全局数组,并且我有通过 URL 传递的数据,但不是文件数据。 我真的在这个上进行了搜索和刮擦,所以任何帮助都表示赞赏。 String strURL = sendToURL + "?ACTION=POST&LEN=" + imgBytes.length + "&Fname=picture.png"; try{ URL urlServlet = new URL(strURL); URLConnection sCon = urlServlet.openConnection(); sCon.setDoInput(true); sCon.setDoOutput(true); if (sCon.getAllowUserInteraction()) { sCon.setAllowUserInteraction(true); } sCon.setUseCaches(false); sCon.setDefaultUseCaches(false); sCon.setRequestProperty("Content-Type", "text/html"); sCon.setRequestProperty("Connection",

2021-12-07 03:48:54    分类:技术分享    java   php   applet   dataoutputstream

Java sockets: DataOutputStream or OutputStream?

I'm still relatively new to sockets, and I haven't seen any information regarding this subject. To write to a connected socket, you can either use socket.getOutputStream().write Or create a new DataOutputStream from the socket OutputStream and write to that. What is considered "good practice", using a DataOutputStream or OutputStream? Most of the examples I find on the internet use DataOutputStream (to send Strings, such as in a two way chat). Are there any advantages or disadvantages from using DataOutputStream over OutputStream? Is there any difference in performance that is noticeable

2021-11-28 13:57:03    分类:问答    java   sockets   networking   dataoutputstream

writeDouble() method of DataOutputStream is writing data in text document in encoded form

I have the following code public static void main(String aed[]){ double d=17.3; try{ DataOutputStream out=null; out=new DataOutputStream(new BufferedOutputStream(new FileOutputStream("new.txt"))); out.writeDouble(d); out.flush(); }catch(FileNotFoundException fnf){ fnf.printStackTrace(); }catch(IOException io){ io.printStackTrace(); } } Now I am writing this double value to a text file new.txt , but following value is getting in text file @1LÌÌÌÌÍ But when i use out.writeUTF(""+d) It works fine. Please explain the encoding that is going on here.

2021-11-26 08:50:08    分类:问答    java   dataoutputstream

writeUTF(String s) vs writeObject(String s)

In this Java project I'm working on for university, I have a situation where I am currently sending strings through the network successfully using streamOut = ObjectOutputStream streamIn = ObjectInputStream streamOut.writeUTF(msgs.peek()); where msgs is a linked blocking queue, receiving it with String in = streamIn.readUTF(); however, I would like to use an ObjectInputStream and an ObjectOutputStream. I have initialized them both in the constructor and I flush the ObjectOutputStream after constructing it, I read somewhere you have to do this. I want to send both Strings and another Object

2021-11-25 06:35:05    分类:问答    java   networking   serialization   dataoutputstream

使用 DataOutputStream 将 int 写入文件(Write int to file using DataOutputStream)

问题 我正在生成随机整数并尝试将它们写入文件。 问题是当我打开我创建的文件时,我没有找到我的整数,而是一组符号,如正方形等......这是编码问题吗? import java.io.DataOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class GenerateBigList { public static void main(String[] args) { //generate in memory big list of numbers in [0, 100] List list = new ArrayList<Integer>(1000); for (int i = 0; i < 1000; i++) { Double randDouble = Math.random() * 100; int randInt = randDouble.intValue(); list.add(randInt); } //write it down to

2021-11-19 19:04:14    分类:技术分享    java   dataoutputstream

为什么它在 httpUrlConnection 上返回内部服务器错误?(Why it returns Internal Server Error on httpUrlConnection?)

问题 我正在开发一个可以将不同文件发送到 Web 服务器的应用程序。此外,我想发送大文件,为了做到这一点,我需要对文件进行分块。 但是当我将文件发送到服务器时,没有上传任何内容。 我不知道我发送文件的方式是否有错误,它在我的响应中给出了错误 500(内部服务器错误)。我不认为服务器是问题,因为当我上传文件时使用multiPartEntity 它可以工作,但是当我使用 BufferedInputStream 和 DataOutputStream 时它不起作用。 请帮助我并告诉我的代码有什么问题,为什么它无法发送我的文件。 这是我到目前为止: String samplefile = "storage/sdcard0/Pictures/Images/picture.jpg"; File mFile = new File(samplefile); int mychunkSize = 2048 * 1024; final long size = mFile.length(); final long chunks = size < mychunkSize? 1: (mFile.length() / mychunkSize); int chunkId = 0; try { BufferedInputStream stream = new BufferedInputStream(new

2021-11-19 03:09:47    分类:技术分享    android   httpurlconnection   dataoutputstream

Why it returns Internal Server Error on httpUrlConnection?

I'm developing an application that can send different files to web server.Also I want to send large files, in able to do this I need to chunk the files. But when I'm sending the files to server nothing is uploaded. I don't know if there's error on how I'm sending the files and it gives an error 500 (internal server error) on my response.I don't think the server is the problem because when I'm uploading a file using multiPartEntity it works but when Im using BufferedInputStream and DataOutputStream it doesn't work. Please help me and tell what's wrong on my code why it can't send my files. Here

2021-11-12 14:45:25    分类:问答    android   httpurlconnection   dataoutputstream

receive output from java DataOutputStream in a php page

I have a java applet which I am using to send a file back to my server with - on the server end I want to receive this on a php page. Below is the java code which is doing the sending, on the php side of things I have checked the global arrays and I have the data passed by the URL, but not the file data. I have really searched and scratched on this one so any help appreciated. String strURL = sendToURL + "?ACTION=POST&LEN=" + imgBytes.length + "&Fname=picture.png"; try{ URL urlServlet = new URL(strURL); URLConnection sCon = urlServlet.openConnection(); sCon.setDoInput(true); sCon.setDoOutput

2021-11-12 10:07:32    分类:问答    java   php   applet   dataoutputstream

Write int to file using DataOutputStream

I'm generating random ints and trying to write them down to a file. The problem is when I open the file I've created I don't find my ints but a set of symbols like squares etc... Is it a problem of encoding ? import java.io.DataOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class GenerateBigList { public static void main(String[] args) { //generate in memory big list of numbers in [0, 100] List list = new ArrayList<Integer>(1000); for (int i = 0; i <

2021-11-12 00:30:33    分类:问答    java   dataoutputstream

解决java.lang.outofmemory错误导致一半文件上传到服务器(Resolving java.lang.outofmemory error causing half of the file to be uploaded to server)

问题 我正在尝试将大型视频文件上传到服务器。 我写了一段适用于图像的代码,所以我想我也应该为视频工作。 我写了下面的代码。 public int uploadFile(String sourceFileUri) { String fileName = sourceFileUri; //Log.v("ONMESSAGE", "File type is " + filetype + "File name is " + fileName); HttpURLConnection conn = null; DataOutputStream dos = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; File sourceFile = new File(sourceFileUri); if (!sourceFile.isFile()) { dialog.dismiss(); runOnUiThread(new Runnable() { public void run() { Toast

2021-10-22 11:48:00    分类:技术分享    java   android   httpurlconnection   fileinputstream   dataoutputstream