public static void main(String[] args) {
File f=new File("C:\\world.txt");//新建一个文件对象,如果不存在则创建一个该文件
FileWriter fw;
try {
fw=new FileWriter(f);
String str="hello world";
fw.write(str);//将字符串写入到指定的路径下的文件中
fw.close();
} catch (IOException e) { e.printStackTrace(); }
}
public static void main(String args[]){
File f= new File("C:\\world.txt") ;
InputStream input = null ;
// 准备好一个输入的对象
try {
input = new FileInputStream(f) ;
byte b[] = new byte[1024] ;
// 所有的内容都读到此数组之中
input.read(b) ;
// 读取内容 网络编程中 read 方法会阻塞
input.close() ;
System.out.println("内容为:" + new String(b)) ;
}
public static void main(String args[]){
File f= new File("C:\\world.txt") ;
// 声明File对象
OutputStream out = null ;
// 准备好一个输出的对象
out = new FileOutputStream(f) ;
// 通过对象多态性,进行实例化
String str = "Hello World!!!" ;
// 准备一个字符串
byte b[] = str.getBytes() ;
// 只能输出byte数组,所以将字符串变为byte数组
out.write(b) ;
// 将内容输出,
out.close() ;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有