Posted By:
Yondon_Erdem
Posted On:
Sunday, October 3, 2004 08:17 PM
Hi. I used this example from sdk. But why it show me wrong text instead of hello world after I use read function. Here is that function: System.out.println(inBuf); System.out.println(outBuf); Here is source code: int MIN_SPACE = 100; String fileName = "testfile"; String newName = "testfile1"; byte[] outBuf = "Hello, World!".getBytes(); byte[] inBuf = new byte[15]; /* Check if there is enough space available */ if (File.spaceAvailable() < MIN_SPACE) throw new IOException("Not enough MMC space"); /* Create and open new file */ File file = new File(); int fileDesc = file.open(fileName)
More>>
Hi.
I used this example from sdk. But why it show me wrong text instead of hello world after I use read function. Here is that function:
System.out.println(inBuf);
System.out.println(outBuf);
Here is source code:
int MIN_SPACE = 100;
String fileName = "testfile";
String newName = "testfile1";
byte[] outBuf = "Hello, World!".getBytes();
byte[] inBuf = new byte[15];
/* Check if there is enough space available */
if (File.spaceAvailable()
< MIN_SPACE)
throw new IOException("Not enough MMC space");
/* Create and open new file */
File file = new File();
int fileDesc = file.open(fileName);
if ( fileDesc
< 0)
throw new IOException("Failed to open file");
/* Write "Hello, world!" string to the file */
if ( file.write( fileDesc, outBuf, 0, outBuf.length ) != outBuf.length )
throw new IOException("Error in writing file");
/* Check the file lenght */
//if (file.length(fileDesc) != outBuf.length)
//throw new IOException("Erroneous file");
/* Read "World" using seek() and read() methods */
if (file.seek(fileDesc, 0) != 0)
throw new IOException("Error in seek() for file");
if (file.read(fileDesc, inBuf, 0, 10) != 10)
throw new IOException("Error in reading file");
System.out.println(inBuf);
System.out.println(outBuf);
/* Close file */
if (file.close(fileDesc)
< 0)
throw new IOException("Failed to close file");
/* Now use methods that don't require file opening */
/* Rename */
if (File.rename(fileName, newName)
< 0)
throw new IOException("Failed to rename file");
/* Check existence */
if (File.exists(newName)
< 0)
throw new IOException("File does not exists");
/* Copy back */
if (File.copy(newName, fileName)
< 0)
throw new IOException("Failed to copy file");
/* Append string using debugWrite() */
if (File.debugWrite(fileName, "Debug string")
<= 0)
throw new IOException("Failed to write debug string");
please help me.
<<Less