07输入输出重点.ppt

  1. 1、本文档共39页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* try { while (true) { price = in.readDouble(); in.readChar(); // throws out the tab unit = in.readInt(); in.readChar(); // throws out the tab desc = in.readUTF(); System.out.println(Youve ordered + unit + units of + desc + at $ + price); total = total + unit * price; } } catch (EOFException e) { } System.out.println(For a TOTAL of: $ + total); in.close(); } } Youve ordered 12 units of Java T-shirt at $19.99 Youve ordered 8 units of Java Mug at $9.99 Youve ordered 13 units of Duke Juggling Dolls at $15.99 Youve ordered 29 units of Java Pin at $3.99 Youve ordered 50 units of Java Key Chain at $4.99 For a TOTAL of: $892.88 7-4 * Java中,标准输入是键盘,标准输出是加载Java程序的命令窗口。 从键盘读入数据或向屏幕输出数据是十分常见的操作,每次操作都创建I/O流将影响系统的运行效率,为此Java在System类中定义了与系统I/O相联系的3个流: ?System.in public static final InputStream in ?System.out public static final PrintStream out ?System.err public static final PrintStream err System类的所有变量和方法都是static。 常用I/O流类—标准I/O 7-5 * 文件 Java.io.File 文件类是外存文件和目录的抽象表示,用来操作文件和获得文件信息,但不提供对文件数据读取的方法。 可以得到文件或目录的描述信息,包括文件名、路径、可读写性、长度等,还可以新建目录,文件创建、改名、删除,列出一个目录中所有的文件或满足某种模式的文件等。 ?创建文件对象 public File(String pathname) public File(String parent, String child) public File(File parent, String child) 例如:File myFile=new File(d:\\works, source\\myfile.txt); * 文件测试与实用方法 ?文件名 String getName( ) String getPath( ) String getAbsolutePath( ) String getParent( ) boolean renameTo(File dest) ?文件信息测试 boolean exists( ) boolean canWrite( ) boolean canRead( ) boolean isFile( ) boolean isDirectory( ) boolean isAbsolute( ) ?获取一般信息与常用操作 long length( ) long lastModified( ) boolean delete( ) ?目录操作 String[] List( ) boolean mkdir( ) 7-6 * RandomAccessFile类同时实现了DataInput和DataOutput接口,提供了对文件随机存取的功能,利用这个类可以在文件的任何位置读取或写入数据。 例:从zip文件中读取特定文件 随机存取文件类-RandomAccessFile * 随机存取文件类-Ra

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档