SimonHu-real 2017-05-17 11:45 采纳率: 0%
浏览 2025
已结题

JAVA中文件操作使用lastindexof获得后缀名的问题

代码如下,我输入E:\Application software\AUTO专杀.rar,追踪index函数返回的是6,也就是我的suffix是plication software\AUTO,试了很多别的文件路径,都找不到最后的那个".",请高手指教下为什么,是E:\的问题吗?

 package javaapplication1;

import java.io.*;
import java.text.DateFormat;
import java.util.Date;
import javafx.scene.shape.Path;

public class One {

    public static void main(String[] args) throws Exception {
        String path, Fsuffix;
        int index;
        Date d = new Date();
        String s;
        s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
        BufferedReader bin = new BufferedReader(new InputStreamReader(System.in, "gb2312"));
        path = bin.readLine();
        File f1 = new File(path);
        //System.out.println(path);
        //index = f1.getName().lastIndexOf(".");
        //Fsuffix = Path.
        File f2 = new File("d:\\" + s+"" +".rar");
        if (f2.exists()) {
            f2.delete();
        }
        f2.createNewFile();
        RandomAccessFile RR = new RandomAccessFile(f1, "r");
        RandomAccessFile RW = new RandomAccessFile(f2, "rw");
        TH_FILE_RW p1=new TH_FILE_RW(RR,RW,0,(long)(f1.length()/2));
        TH_FILE_RW p2=new TH_FILE_RW(RR,RW,1+(long)(f1.length()/2),f1.length());
        p1.start();
        p2.start();

    }
}
   class TH_FILE_RW extends Thread {
        RandomAccessFile RR;
        RandomAccessFile RW;
        long begin, end;

        public TH_FILE_RW(RandomAccessFile RR, RandomAccessFile RW, long begin, long end) {
            this.RR = RR;
            this.RW = RW;
            this.begin = begin;
            this.end = end;
        }
        long num = 0;
        byte bt[] = new byte[1024];

        public void run() {
            while (true) 
            {
                try{
                int count=RR.read(bt);
                num+=count;
                if(count<=0)
                {
                    break;
                }
                if(num>=(end-begin))
                {
                    count=count-(int)(num-(end-begin));
                    RW.write(bt, 0, count);
                    break;
                }
                RW.write(bt, 0, count);
                }catch (Exception e)
                {
                    e.printStackTrace();
                }

            }
        }
    }

  • 写回答

1条回答

  • oyljerry 2017-05-17 12:29
    关注

    从后往前查找.和\。得到之间的字符串

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况