I have a method can convert to a data to byte array and i must post it to a php web site. I am gonna use a java socket now. preparing that if i did i will add it here
it is data to byte[] methods , i found it in PDF to byte array and vice versa
public static byte[] readFully(InputStream stream) throws IOException
{
byte[] buffer = new byte[8192];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int bytesRead;
while ((bytesRead = stream.read(buffer)) != -1)
{
baos.write(buffer, 0, bytesRead);
}
return baos.toByteArray();
}
public static byte[] loadFile(String sourcePath) throws IOException
{
InputStream inputStream = null;
try
{
inputStream = new FileInputStream(sourcePath);
return readFully(inputStream);
}
finally
{
if (inputStream != null)
{
inputStream.close();
}
}
}
Here how to post a byte to php web site...
public static void postMybyte (String out)
{
try {
// Construct data
String data = URLEncoder.encode(out, "UTF-8") ;
// Send data
URL url = new URL("");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(" --->>>>"+line);
}
wr.close();
rd.close();
} catch (Exception e)
{
}
}