try {
//File file=new File("D:\\cs\\ceshi.txt");
// File file=new File("D:"+File.separator+"cs"+File.separator+"ceshi.txt");
// System.out.println("file.getName() = " + file.getName());
// System.out.println("file.getParent() = " + file.getParent());
// System.out.println("file.getParentFile() = " + file.getParentFile());
// System.out.println("file.getPath() = " + file.getPath());
// System.out.println("file.isAbsolute() = " + file.isAbsolute());
// System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());
// System.out.println("file.canRead() = " + file.canRead());
// System.out.println("file.canWrite() = " + file.canWrite());
// System.out.println("file.exists() = " + file.exists());
// System.out.println("file.isDirectory() = " + file.isDirectory());
// System.out.println("file.isFile() = " + file.isFile());
// System.out.println("file.lastModified() = " + new Date(file.lastModified()));
// System.out.println("file.length() = " + file.length());
// File f2=new File("\\java");
// System.out.println("f2.getAbsolutePath() = " + f2.getAbsolutePath());
// System.out.println("f2.exists() = " + f2.exists());
// System.out.println("f2.mkdir() = " + f2.mkdir());
/*File file=new File("D:"+File.separator+"cs"+File.separator+"ceshi.txt");
RandomAccessFile rdf=null;
//读写模式
rdf=new RandomAccessFile(file,"rw");
String name="zhangsan";
int age=97;
rdf.writeBytes(name);
rdf.writeInt(age);
name="lisi ";
age=98;
rdf.writeBytes(name);
rdf.writeInt(age);
name="wangwu ";
age=99;
rdf.writeBytes(name);
rdf.writeInt(age);
rdf.close();*/
/*File file=new File("D:"+File.separator+"cs"+File.separator+"ceshi.txt");
RandomAccessFile rdf=null;
//读写模式
rdf=new RandomAccessFile(file,"r");
String name=null;
int age=0;
byte[] b = new byte[8];
//跳过第一个人的信息
rdf.skipBytes(12);
for (int i = 0; i < b.length; i++) {
//读取一个字节
b[i]=rdf.readByte();
}
name=new String(b);
age=rdf.readInt();
System.out.println("第二个人的信息 --> 姓名:" + name + ";年龄:" + age) ;
// 读取第一个人的信息// 指针回到文件的开头
rdf.seek(0) ;
for (int i = 0; i < b.length; i++) {
b[i]=rdf.readByte();
}
name = new String(b) ; // 将读取出来的byte数组变为字符串
age = rdf.readInt() ; // 读取数字
System.out.println("第一个人的信息 --> 姓名:" + name + ";年龄:" + age) ;
rdf.skipBytes(12) ; // 跳过第二个人的信息
for (int i = 0; i < b.length; i++) {
b[i]=rdf.readByte();
}
name = new String(b) ; // 将读取出来的byte数组变为字符串
age = rdf.readInt() ; // 读取数字
System.out.println("第三个人的信息 --> 姓名:" + name + ";年龄:" + age) ;
rdf.close();*/
/*File file=new File("D:"+File.separator+"cs"+File.separator+"test.txt");
OutputStream out=new FileOutputStream(file);
String str="Hello World";
byte[] bytes = str.getBytes();
out.write(bytes);
// out.close();*/
/* File file=new File("D:"+File.separator+"cs"+File.separator+"test2.txt");
Writer writer=new FileWriter(file);
String str="Hello World 2";
byte[] bytes = str.getBytes();
writer.write(str);
writer.flush();
// writer.close();*/
/*
//读取txt每一行数据
File file=new File("D:"+File.separator+"cs"+File.separator+"test2.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String str=null;
while ((str=reader.readLine())!=null){
System.out.println("str = " + str);
}
reader.close();*/
/*
//获取输入的第一个字符
System.out.print("Enter a Char:");
char i = (char)System.in.read();
System.out.println("Yout Enter Char is:" + i);*/
} catch (Exception e) {
e.printStackTrace();
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)