D
De Wayne Dantzler
I'm new to java and I'm trying to download a file from a url. I've tried
the following scheme given below, but the contents of the file is
garbage. One file is binary and the other is xml. I always get an
EOFException even though I check for a -1 return value. Any clues?
public void writeBinaryData2File( String fileOut ) throws IOException
{
BufferedInputStream bis = new
BufferedInputStream(_MyUrl.openStream());
DataInputStream dataIn = new DataInputStream(bis);
FileOutputStream fos = new FileOutputStream(fileOut);
DataOutputStream dataOut = new DataOutputStream( fos );
byte bdata;
while( (bdata = dataIn.readByte()) != -1 )
{
dataOut.writeByte( bdata );
}
}
public void writeXml2File( String fileOut ) throws IOException,
EOFException
{
BufferedInputStream bis = new
BufferedInputStream(_MyUrl.openStream());
DataInputStream dataIn = new DataInputStream(bis);
FileWriter fw = new FileWriter(fileOut);
int cdata;
try
{
while((cdata = dataIn.readInt()) != -1 )
{
fw.write( cdata );
}
}catch( EOFException e) { fw.close(); e.printStackTrace(); }
}
the following scheme given below, but the contents of the file is
garbage. One file is binary and the other is xml. I always get an
EOFException even though I check for a -1 return value. Any clues?
public void writeBinaryData2File( String fileOut ) throws IOException
{
BufferedInputStream bis = new
BufferedInputStream(_MyUrl.openStream());
DataInputStream dataIn = new DataInputStream(bis);
FileOutputStream fos = new FileOutputStream(fileOut);
DataOutputStream dataOut = new DataOutputStream( fos );
byte bdata;
while( (bdata = dataIn.readByte()) != -1 )
{
dataOut.writeByte( bdata );
}
}
public void writeXml2File( String fileOut ) throws IOException,
EOFException
{
BufferedInputStream bis = new
BufferedInputStream(_MyUrl.openStream());
DataInputStream dataIn = new DataInputStream(bis);
FileWriter fw = new FileWriter(fileOut);
int cdata;
try
{
while((cdata = dataIn.readInt()) != -1 )
{
fw.write( cdata );
}
}catch( EOFException e) { fw.close(); e.printStackTrace(); }
}