2013-11-19
展开全部
将那个text文件用流读进来,然后拆分装进string型数组中,然后用for循环倒叙到另一个空数组中,最后把倒序完的数组写入text文件里。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-19
展开全部
package cn.rain.demo;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
public class IO {
private RandomAccessFile raf;
public void getTxt(){
try {
raf = new RandomAccessFile("F:\\rain.txt", "rw");
int lenth = (int) raf.length();
ByteBuffer bb = ByteBuffer.allocate(lenth);
raf.getChannel().read(bb);
byte[] str = new byte[lenth];
str = bb.array();
byte[] strChanged = new byte[lenth];
for(int i = 0; i < lenth; i++)
{
strChanged[i] = str[lenth - 1 - i];
}
System.out.print(new String(strChanged));
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
IO io = new IO();
io.getTxt();
}
}
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
public class IO {
private RandomAccessFile raf;
public void getTxt(){
try {
raf = new RandomAccessFile("F:\\rain.txt", "rw");
int lenth = (int) raf.length();
ByteBuffer bb = ByteBuffer.allocate(lenth);
raf.getChannel().read(bb);
byte[] str = new byte[lenth];
str = bb.array();
byte[] strChanged = new byte[lenth];
for(int i = 0; i < lenth; i++)
{
strChanged[i] = str[lenth - 1 - i];
}
System.out.print(new String(strChanged));
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
IO io = new IO();
io.getTxt();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询