Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“什么是”呢;文件";java中的数据类型。。? import java.io.*; 类拆分文件 { 私有文件fSplit; 私有整数大小字节; 私人整数计数; 公共静态void main(字符串[]args)引发IOException { Console con=System.Console(); 字符串文件名; int size=0; System.out.print(“输入要拆分的文件名:”); fileName=con.readLine(); System.out.print(“输入目标文件的大小:”); size=Integer.parseInt(con.readLine()); SplitFile sf=新的SplitFile(文件名、大小); sf.split(); } 公共文件checkFileExists(字符串fName) { 文件f=新文件(fName); 如果(!f.exists()) { System.out.println(“文件”+fName+“不存在”); 系统出口(0); } 返回f; } public int validateSize(int s) { if(fSplit.length()_Java_File - Fatal编程技术网

“什么是”呢;文件";java中的数据类型。。? import java.io.*; 类拆分文件 { 私有文件fSplit; 私有整数大小字节; 私人整数计数; 公共静态void main(字符串[]args)引发IOException { Console con=System.Console(); 字符串文件名; int size=0; System.out.print(“输入要拆分的文件名:”); fileName=con.readLine(); System.out.print(“输入目标文件的大小:”); size=Integer.parseInt(con.readLine()); SplitFile sf=新的SplitFile(文件名、大小); sf.split(); } 公共文件checkFileExists(字符串fName) { 文件f=新文件(fName); 如果(!f.exists()) { System.out.println(“文件”+fName+“不存在”); 系统出口(0); } 返回f; } public int validateSize(int s) { if(fSplit.length()

“什么是”呢;文件";java中的数据类型。。? import java.io.*; 类拆分文件 { 私有文件fSplit; 私有整数大小字节; 私人整数计数; 公共静态void main(字符串[]args)引发IOException { Console con=System.Console(); 字符串文件名; int size=0; System.out.print(“输入要拆分的文件名:”); fileName=con.readLine(); System.out.print(“输入目标文件的大小:”); size=Integer.parseInt(con.readLine()); SplitFile sf=新的SplitFile(文件名、大小); sf.split(); } 公共文件checkFileExists(字符串fName) { 文件f=新文件(fName); 如果(!f.exists()) { System.out.println(“文件”+fName+“不存在”); 系统出口(0); } 返回f; } public int validateSize(int s) { if(fSplit.length(),java,file,Java,File,文件对象就是一个用于处理文件的对象,您可以在文档中阅读它。基于文档 文件和目录路径名的抽象表示 文件是一种引用类型。它用于处理文件(如创建文件)。通过查看此文档,您将更容易理解它 更新 通过查看前面答案中的注释,我发现您不知道/不熟悉java中的不同数据类型,有两种数据类型 基本数据类型(字符、整型、布尔型) 引用类型/对象(用户) 已定义的类,超类对象,在您的例子中 文件) 我从未听说过文件数据类型。。请告诉我。给定的代码用于什么?文件不是数据类型。问之前你研究过了吗?对不起,第四行是..私有

文件对象就是一个用于处理文件的对象,您可以在文档中阅读它。

基于文档

文件和目录路径名的抽象表示

文件
是一种引用类型。它用于处理文件(如创建文件)。通过查看此文档,您将更容易理解它

更新

通过查看前面答案中的注释,我发现您不知道/不熟悉java中的不同数据类型,有两种数据类型

  • 基本数据类型(字符、整型、布尔型)
  • 引用类型/对象(用户) 已定义的类,超类
    对象
    ,在您的例子中
    文件

  • 我从未听说过文件数据类型。。请告诉我。给定的代码用于什么?文件不是数据类型。问之前你研究过了吗?对不起,第四行是..私有文件fSplit。非私有字符串fSplitJava类的文档非常丰富。阅读他们的文档:@pradeep。。如果不是数据类型。。那么它是什么呢?..@joy一个可以被实例化为对象的类,就像java中的大多数东西一样(例如:string类)ohkay。。它是java中预定义的类吗?如果您指的是“File”对象,那么它是java中预定义的。但是您也可以创建自己的引用类型,但这已经超出了这个问题的范围。@joy,现在是学习Java基础知识的时候了,Oracle网站有一个很好的教程。谢谢sooo Muchh…)请随意点击复选标记;)
    import java.io.*;
    
    class SplitFile    
    {    
        private File fSplit;
        private int sizeInBytes;
    
        private int count;
    
        public static void main(String[] args) throws IOException
        {    
            Console con = System.console();
    
            String fileName;
    
            int size = 0;
    
            System.out.print("Enter the file name to split: ");
    
            fileName = con.readLine();
    
            System.out.print("Enter the size of the target file: ");
    
            size = Integer.parseInt(con.readLine());
    
            SplitFile sf = new SplitFile(fileName, size);
    
            sf.split();
    
        }
    
        public File checkFileExists(String fName)    
        {    
            File f = new File(fName);
    
            if (!f.exists())    
            {    
                System.out.println("File " + fName + " does not exists");
    
                System.exit(0);
    
            }
    
            return f;
    
        }
    
        public int validateSize(int s)    
        {    
            if (fSplit.length() < s)    
            {
    
                System.out.println("Invalid Size");
    
                System.exit(0);
    
            }
    
            return s;
    
        }
    
        public String createNextFileName()    
        {    
            ++count;
    
            String fileName;
    
            fileName = "part_" + count + "." + fSplit.getName();
    
            return fileName;
    
        }
    
        public SplitFile(String fName, int s)    
        {
    
            fSplit = checkFileExists(fName);
    
            sizeInBytes = validateSize(s);
    
            count = 0;
    
        }
    
        public void split() throws IOException
    
        {
    
            FileInputStream fis = new FileInputStream(fSplit);
    
            BufferedInputStream bis = new BufferedInputStream(fis);
    
            File fileSegment = new File(createNextFileName());
    
            FileOutputStream fos = new FileOutputStream(fileSegment);
    
            BufferedOutputStream bos = new BufferedOutputStream(fos);
    
            int ch;
    
            int currentByteCount = 0;
    
            while ((ch = bis.read()) != -1)
    
            {
    
                bos.write(ch);
    
                ++currentByteCount;
    
                if (currentByteCount == sizeInBytes)
    
                {
    
                    bos.close();
    
                    fos.close();
    
                    fileSegment = new File(createNextFileName());
    
                    fos = new FileOutputStream(fileSegment);
    
                    bos = new BufferedOutputStream(fos);
    
                    currentByteCount = 0;
    
                }
    
            }
    
            bis.close();
    
            fis.close();
    
            bos.close();
    
            fos.close();
    
        }
    
    }