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 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?