输入输出流的总结以及toyCode

本文详细介绍了 Java 中的基本 I/O 操作,包括 InputStream 和 OutputStream 的使用方法,以及如何通过 FileInputStream 和 FileOutputStream 进行文件读写。文章还提供了具体的代码示例,展示了如何复制文件和读取文件内容。
四个抽象类
InputStream//一次读一个字节
OutputStream//一次写一个字节
Reader//一次读一个字符(2个字节)
Writer 一次写1个字符(2个字节)
针对于内存(程序)来说输入还是输出


int read()throws IOException
读一个字节并以整数形式返回(0-255)
如果返回-1已经到达输入流的末尾




读取一系列字符并存储到一个数组 buffer
int read(byte [] buffer)throws IOException
返回实际读取的字节数,如果读取前已经到输入流末尾,返回-1




int read(String [] buffer,int offset, int length)
读取length个字节,并存储到buffer字节数组里,从offSet开始


节点流类型(单纯的一个管道)
File 
FileReader FileWriter
FileInputStream FileOutputStream


public class TestFileInputStream{
public static void main(String [] args){
int b =0;
FileInputStream in = null;
try{
in = new FileInputStream("d:\\share");
}catch(FileNotFoundException){
System.out.println("程序找不到");
}


try{
long num =0;
while((b = in.read())!=-1){
System.out.println(char(b));
num++;
}
in.close();
System.out.println("一共读取了多少个字节"+num);
System.out.println();
}catch(IOException e){
System,out.println("文件读取错误");
System.exit(-1);
}
}
}
 


FileOutputStream(""),在没有该文件的情况下,自动生成一个文件
File和inputStream不产生一个新文件。




public class TestFileOutputStream{
public static void main(String [] args){
FileInputStream in = null;
FileOutputStream out = null;
int b;
  try{
in = new InputStream("d://a.txt");
out = new FileStream("d://b.txt");
while((b=in.read())!=-1){
out.write(b);
}
in.close();
out.close();
}catch(FileNotFoundException e){
System.out.println("文件没有找到");
}catch(IOException e){
System.out.println("文件读取错误");
}
System.out.println("文件已经复制");
}
}


public class TestFile{
public static void main(){
FileReader fr = null;
int c= 0;
try{
fr = new FileReader();
while((c=fr.read())!=-1){//按照一个字符来读(2个字节)
//中英文打印全部正常
System.out.println((char)c);
}
fr.close();
}catch(FileNotFoundExcption e){
System.out.println("文件没有找到");
}catch(IOException ioe){
System.out.pritnln("文件读写异常");
}
}
}


public static void main(){
FileWriter fw = null;
try{
fw = new FileWriter("d:\\aaa");//没有这个文件的话
//自动创建文件,但目录必须自己手动创建
for(int i=0;i<4000;i++){
fw.wtite(i);
}
fw.close();
}catch(IOException ioe){
Syst..
System.exit(-1);
}catch(FileNotFoundException e){
sys..
}


}


 
public class Copy{
public static void main(String [] args){
FileReader fr = null;
FileWriter fw = null;
int i;
try{
fr = new FileReader("D:\\resource.txt");
fw = new FileWriter("D:\\destinition.txt");
while((i=fr.read())!=-1){
fw.write(i);
}
fr.close();
fw.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
struct Functions { float2 csqr( float2 a ) { return float2( a.x*a.x - a.y*a.y, 2.*a.x*a.y ); } float2 iSphere( in float3 ro, in float3 rd, in float4 sph )//from iq { float3 oc = ro;// - sph.xyz; float b = dot( oc, rd ); float c = dot( oc, oc ) - sph.w*sph.w; float h = 1.0; //b*b - c; return float2(-b-h, -b+h ); } float map(in float3 p, float2 sctime) { float res = 0.; float3 c = p; c.xy = c.xy * sctime.x + float2(c.y, c.x) * sctime.y; for (int i = 0; i < 10; ++i) { p =.7*abs(p)/dot(p,p) -.7; p.yz= csqr(p.yz); p=p.zxy; res += exp(-19. * abs(dot(p,c))); } return res/2.; } float3 raymarch( in float3 ro, float3 rd, float2 tminmax , float2 sctime) { //tminmax += float2(1.,1.) * sin( iTime * 1.3)*3.0; float3 one3 = float3(1.,1.,1.); float3 t = one3 * tminmax.x; float3 dt = float3(.07, 0.02, 0.05); float3 col= float3(0.0,0.0,0.0); float3 c = one3 * 0.; for( int i=0; i<64; i++ ) { float3 s = float3(2.0, 3.0, 4.0); t+=dt*exp(-s*c); float3 a = step(t,one3*tminmax.y); float3 pos = ro+t*rd; c.x = map(ro+t.x*rd, sctime); c.y = map(ro+t.y*rd, sctime); c.z = map(ro+t.z*rd, sctime); col = lerp(col, .99*col+ .08*c*c*c, a); } float3 c0 = float3(0.4,0.3,0.99); float3 c1 = float3(0.9,0.7,0.0); float3 c2 = float3(0.9,0.1,0.2); return c0 * col.x + c1 * col.y + c2 * col.z; } }; Functions f; //float time = iTime; //unity直接获取不需要调用API // float2 q = fragCoord.xy / iResolution.xy; //float2 p = -1.0 + 2.0 * q; //p.x *= iResolution.x/iResolution.y; //适配UV拉伸效果 把中心点一直锚在中心值 float2 m = float2(0.0,0.0); float3 ro = float3(6.0,6.0,6.0); float3 ta = float3( 0.0 , 0.0, 0.0 ); float3 ww = normalize( ta - ro ); float3 uu = normalize( cross(ww,float3(0.0,1.0,0.0) ) ); float3 vv = normalize( cross(uu,ww)); float3 rd = normalize( p.x*uu + p.y*vv + 4.0*ww ); float2 tmm = f.iSphere( ro, rd, float4(0.,0.,0.,2.) ); // raymarch float3 col = f.raymarch(ro,rd,tmm, float2(sin(iTime), cos(iTime))); // shade col = .5 *(log(1.+col)); col = clamp(col,0.,1.); return float4( col, 1.0 ); 这个代码我是在UEshader上自定义函数写的 目前能呈现出效果 效果是这个网站上的https://www.shadertoy.com/view/4tyfDm?__cf_chl_tk=c0j.1zP8CXos3wVjuRDNYZqoRYkmtg69UoDlB10uCvM-1762484933-1.0.1.1-9LvqXz8EWKW1Hliv7jR60btt.bIGNjw.MBlqbIcRYGs 我在unityASE中怎么重新实现这样的效果 你注意分析我的代码 的UV是用参数P去呈现的 时间是用iTime 这个参数控制的
最新发布
11-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值