java.io.File写入写出的一个简单实例

本文介绍使用 Java 的 FileInputStream 和 FileOutputStream 进行文件读写的基本操作,包括读取文本文件和图片文件,并提供了实例代码演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} -->

java.io.File 写入写出的一个简单实例

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestIO {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
byte[] b = new byte[17*1024];
// ** txt
// File f = new File("d://test.txt");
// File outF = new File("d://testOut.txt");
// ** jpg
File f = new File("d://
毫无保留.jpg");
File outF = new File("d://
毫无保留Output.jpg");
try
{
FileInputStream fis = new FileInputStream(f);
FileOutputStream fops = new FileOutputStream(outF);
fis.read(b);
fops.write(b);

// ** for see
// String s = new String(b);
// System.out.println(s);

fis.close();
fops.close();
}
catch(FileNotFoundException fnfe)
{
System.out.println("FileNotFoundException fnfe");
fnfe.printStackTrace();
}
catch(IOException ie)
{
System.out.println("IOException ie");
ie.printStackTrace();
}


}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值