java i/o读写
package ioput;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class aaa {
/*public static void main(String[] args) {
args = new String[]{"a","b","c"};
for (int i = 0; i < args.length; i++) {
System.out.println("args[" + i + "] is <" + args[i] + ">");
}
}*/
/*public static void main(String args[]) {
int b;
try {
System.out.println("please Input:");
while ((b = System.in.read()) != -1) {
System.out.print((char) b);
}
} catch (IOException e) {
System.out.println(e.toString());
}
} */
/* public static void main(String args[]) {
String s;
// 创建缓冲区阅读器从键盘逐行读入数据
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(ir);
System.out.println("Unix系统: ctrl-d 或 ctrl-c 退出"
+ "\nWindows系统: ctrl-z 退出");
try {
// 读一行数据,并标准输出至显示器
s = in.readLine();
// readLine()方法运行时若发生I/O错误,将抛出IOException异常
while (s != null) {
System.out.println("Read: " + s);
s = in.readLine();
}
// 关闭缓冲阅读器
in.close();
} catch (IOException e) { // Catch any IO exceptions.
e.printStackTrace();
}
}*/
//从磁盘读数据
/*public static void main(String[] args){
try {
File file = new File("d:/aaa/gbk.txt");
InputStream fileStream = new FileInputStream(file);
InputStreamReader read = new InputStreamReader(fileStream,"utf-8");
BufferedReader bufferedReader = new BufferedReader(read);
String text = null;
while((text =bufferedReader.readLine())!=null){
System.out.println(text);
}
read.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
//数据写入磁盘
public static void main(String[] args){
String path = "d:/tr/rt";
File f = new File(path);
if(!f.exists()){
f.mkdirs();
}
String fileName="test.txt";
File file = new File(f,fileName);
if(!file.exists()){
try {
file.createNewFile();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String s = "1234567890";
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(s);
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
posted on 2015-12-03 10:37 zhaoshuzhan 阅读(119) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?