TextFileReadWrite

TextFileReadWrite - { File inputFileName = new...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 For writing text files ========================================================================== outputFile = null Create the file: File filePathInfo = new File(path, fileName) FileOutputStream outputFile = new FileOutputStream(filePathInfo, APPEND) Write the file: public int writeText(String txt) { int i char[] ch = txt.toCharArray() try { for (i = 0 { outputFile.write( (int) ch[i]) } outputFile.close() } catch (FileNotFoundException ex) // Things might go wrong { return 0 }catch (IOException e) { return 0 } return 1 } To read the data================================================================================ FileReader readFile BufferedReader buffreader Open the file: public int OpenTextFile(String fileName)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { File inputFileName = new File(fileName) int readFlag = 0 try Sheet1 Page 2 { // Try to get an input file stream readFile = new FileReader(inputFileName) buffreader = new BufferedReader(readFile) } catch (FileNotFoundException ex) { return 1 } return 0 } Read from the file: public String ReadOneLine() { String text try { text = buffreader.readLine() } catch (IOException ex) { return null } return text } Close the file: public void CloseRead() { try { buffreader.close() } catch (IOException ex) { System.exit(0) } } Sheet1 Page 3 // Treat as ints for Unicode i < txt.length() i++) // Write the data // Close the file Sheet1 Page 4...
View Full Document

This note was uploaded on 04/18/2008 for the course CIT 295 taught by Professor Purdum during the Fall '08 term at Purdue.

Page1 / 4

TextFileReadWrite - { File inputFileName = new...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online