Files - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Files

Description:

{ System.out.println('File not created'); } catch (IOException e) { // Handle error ... out.close(); } catch (IOException e2) { JOptionPane.showMessageDialog ... – PowerPoint PPT presentation

Number of Views:8
Avg rating:3.0/5.0
Slides: 6
Provided by: leonjo
Category:

less

Transcript and Presenter's Notes

Title: Files


1
Files
  • Dr. L. Jololian

2
Topics Covered
  • Creating a new file object
  • File f new File("myfile.txt")
  • Creating a new file
  • f.createNewFile()
  • Deleting a file
  • file.delete()
  • Saving to a file
  • BufferedWriter out new BufferedWriter(
  • new FileWriter(file))
  • out.write( aString)
  • out.close()

3
Create a New File
import java.io. public class Files public
Files () try File f new
File("myfile.txt") boolean result
f.createNewFile() if (result)
System.out.println("File created")
else System.out.println("File not
created") catch (IOException e)
// Handle error public static void
main(String args) new Files()
4
Deleting a File
File file new File(abc.txt) boolean result
file.delete() if (result) System.out.printl
n("File deleted") else System.out.println("C
annot be deleted")
5
Saving
else if(e.getSource() save e.getSource()
saveButton) int v fc.showSaveDialog(E
ditor.this) File file fc.getSelectedFile()
try BufferedWriter out new
BufferedWriter( new FileWriter(file))
out.write(textarea.getText())
out.close() catch (IOException e2)
JOptionPane.showMessageDialog(null, "Erro
r in saving")
Write a Comment
User Comments (0)
About PowerShow.com