|
Given : DataOutputStream dos
Condition : when passing the following string C3B307EC48ED80AA into dos.writeBytes, the string is changed to C3B307EC48EDACAA
Does anyone no why ?
|
|
|
I couldn't get this to misbehave. See how it does for you.
import java.io.*;
public class DataWriteTest
{
public static void main(String[] args)
{
String s = "C3B307EC48ED80AA";
String filePath = "/forum/dataWriteTest.txt";
System.out.println("write to file: " + s);
writeString(s, filePath);
System.out.println("read from file: " + readString(filePath));
}
private static void writeString(String s, String destPath)
{
DataOutputStream dos = null;
try
{
dos = new DataOutputStream(
new FileOutputStream(destPath));
dos.writeBytes(s);
dos.close();
}
catch(IOException ioe)
{
System.out.println("write: " + ioe.getMessage());
}
}
private static String readString(String filePath)
{
StringBuilder sb = new StringBuilder(); // j2se 1.4+
// or you can use the legacy StringBuffer
//StringBuffer sb = new StringBuffer();
BufferedReader br = null;
try
{
br = new BufferedReader(
new InputStreamReader(
new FileInputStream(filePath)));
String line;
while((line = br.readLine()) != null)
sb.append(line + "\n");
br.close();
}
catch(IOException ioe)
{
System.out.println("read: " + ioe.getMessage());
}
return sb.toString();
}
}
|
|
|
|
|
on a bit of a side note, how do i convert one thing from another using a user defined number?
I've created 3 Textboxes, 2 so the user can input wat there converting, eg £ to euros then another one to say how many euros r in a pound.
Like the user types in theres 3 euros in a pound in one box. so thats the exchange box.
the user then wants to know how many euros are in a pound, so in the pound text box puts 50, i then want java to look for what the user defined exchange rate was then input the text in the euro field and vice versa. if no exchange is applied then there should be a default of for example 1.
do i have to declare them on the Jframe form? like
int Euro
int pound
int euroPerPound
int Pound per Euro
<Added>
Wrong Forum, Sorry, if anoyone knows tho please help lol
|
|
|
|
|
|
|
// |