「java可以边读边写吗」java可以写程序吗

2023-03-20 10:02:07 38
admin

本篇文章给大家谈谈java可以边读边写吗,以及java可以写程序吗对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java io 流 有一种流是边读边写的 , 还一种 不管文件多大都读到内存中 , 分别叫什么?

边读边写用多线程每个流都可以做到,管道流就是典型的流!

不管文件多大,读到内存那是不可能的,你所说的应该是内存流

内存流典型的流(字节数组流),特点内部封装一个可变长度的数组,

特点就是处理速度快,可对外提供完整数据的数组,非常方便!

试想一下,你一个文件8G大,你能全都读到内存中去?对么....

java如何实现对同一个text文本边写边读

import java.io.*;

import java.lang.*;

import java.util.Scanner;

import java.io.*;

import java.lang.*;

public class Sy2Student

{

public static void main(String []args)

{

Writer Swriter=null;

Scanner s=new Scanner(System.in);

System.out.print("输入学生的人数:");

int Studentpeople=s.nextInt();

String []StudentScore=new String[Studentpeople];

String []StudentName=new String[Studentpeople];

System.out.println("请输入学生的姓名和总分");

for(int i=0;iStudentpeople;i++)

{

StudentName[i]=s.next();

StudentScore[i]=s.next();

System.out.println("\n");

}

int []IntStudentScore=new int[Studentpeople];

for(int n=0;nStudentpeople;n++)

{

IntStudentScore[n]=Integer.parseInt(StudentScore[n]);

}

int StudentScoreMin=IntStudentScore[0];

int StudentScoreMax=IntStudentScore[0];

for(int m=1;mStudentpeople;m++)

{

int AllScore=IntStudentScore[0];

AllScore+=IntStudentScore[m];

//求最低分

if(StudentScoreMinIntStudentScore[m])

StudentScoreMin=IntStudentScore[m];

else

StudentScoreMin=StudentScoreMin;

}

//求最高分

for(int p=0;pStudentpeople;p++)

{

if(StudentScoreMaxIntStudentScore[p])

StudentScoreMax=IntStudentScore[p];

else

StudentScoreMax=StudentScoreMax;

}

try{

Swriter=new FileWriter("Student.txt");

Swriter.write("学生成绩表单\n");

Swriter.write("姓名:\t\t总分:\n");

for(int j=0;jStudentpeople;j++)

{

Swriter.write(StudentName[j]+"\t\t");

Swriter.write(StudentScore[j]+"\n");

}

Swriter.write("最高分:"+StudentScoreMax+"\n");

Swriter.write("最低分:"+StudentScoreMin+"\n");

}catch(IOException e){

e.printStackTrace();

}finally{

if(Swriter!=null)

try{

Swriter.close();

}catch(IOException e){}

}

Reader RStudent=null;

try{

RStudent=new FileReader("Student.txt");

char []buffer=new char[1024];

int offset;

while((offset=RStudent.read(buffer))0)

System.out.println(new String(buffer,0,offset));

}catch(FileNotFoundException e){

e.printStackTrace();

}catch(IOException e){

e.printStackTrace();

}finally{

if(RStudent!=null)

try{

RStudent.close();

}catch(IOException e){}

}

}

}

你可以参考着个程序 我自己写的

Java中如何同时实现不断的读取和不断的写入,

一个死循环搞定。

比如:

while(true){

里面写你的代码,就行!

}

用java读取文件可以一边读取一边写入吗?如果我读取到某行数据,想用其它数据替换或者删除怎么写?

另外写一个文件,把有用的、需要改动的信息写入,最后删除原文件。

java读写同一个文件

读取文件有三种方式,r, w, a,读,覆盖写, 追加写, new FileReader(file)以读的方式打开了文件,两个马上就以new FileWriter(file)方式覆盖写文件,文件自然是空白的,之后你readLine读到的是null,即String line是null,然后你要writer.write(line); 即writer.write(null); 自然报空指针;

建议,如果边读边写,考虑RandomAccessFile类

关于java可以边读边写吗和java可以写程序吗的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

分享
38

忘记密码?

图形验证码