H
Hugh Mackay
I am trying to read in lines from a text file which will then be
written to another file with xml tags and transmitted down a modem.
I can move the text file, and get the size but when I read the
contents and print to screen I get meaningless rubbish.
The text file contains lines like:
20040202 165204, 0000.0.001, 00000000h, S Test
but java spits out this:
????????ë?????ë?????????????????ë?????ë?????????????????ë?????ë?????????????????
ë?????ë?????????????????ë?????ë?????????????????ë?????ë?????????
I am using this code:
try
{
alarmFile = new FileInputStream(target);
} catch (FileNotFoundException e) {
System.out.println(e);
}
FileChannel inChannel = alarmFile.getChannel();
try
{
fileSize = (int)inChannel.size();
System.out.println("Filesize = "+fileSize);
} catch (IOException e) {
System.out.println(e);
}
ByteBuffer buf = ByteBuffer.allocate(fileSize);
StringBuffer str = new StringBuffer(fileSize);
if (target.exists())
{
try
{
while(inChannel.read(buf) != -1)
{
str.append(((ByteBuffer)(buf.flip())).asCharBuffer().toString());
buf.clear();
}
alarmFile.close();
}
catch(IOException e)
{
System.out.println(e);
}
Any ideas? AM I missing something blindingly obvious? (you can
probably guess I am not a great java programmer!)
written to another file with xml tags and transmitted down a modem.
I can move the text file, and get the size but when I read the
contents and print to screen I get meaningless rubbish.
The text file contains lines like:
20040202 165204, 0000.0.001, 00000000h, S Test
but java spits out this:
????????ë?????ë?????????????????ë?????ë?????????????????ë?????ë?????????????????
ë?????ë?????????????????ë?????ë?????????????????ë?????ë?????????
I am using this code:
try
{
alarmFile = new FileInputStream(target);
} catch (FileNotFoundException e) {
System.out.println(e);
}
FileChannel inChannel = alarmFile.getChannel();
try
{
fileSize = (int)inChannel.size();
System.out.println("Filesize = "+fileSize);
} catch (IOException e) {
System.out.println(e);
}
ByteBuffer buf = ByteBuffer.allocate(fileSize);
StringBuffer str = new StringBuffer(fileSize);
if (target.exists())
{
try
{
while(inChannel.read(buf) != -1)
{
str.append(((ByteBuffer)(buf.flip())).asCharBuffer().toString());
buf.clear();
}
alarmFile.close();
}
catch(IOException e)
{
System.out.println(e);
}
Any ideas? AM I missing something blindingly obvious? (you can
probably guess I am not a great java programmer!)