TempFile Java程序不能在linux上运行

时间:2017-10-17 07:04:20

标签: java linux unix buffer

我有一个程序可以创建一个tempFile并在其中写入数据。

该程序适用于Windows但不适用于Linux,有人可以告诉我原因吗?

这是一个以输入文件作为参数执行的脚本。

这就是我在代码中所做的:

if (args.length > 0){
        for(int i=0; i<args.length; i++){
            fileList.add(new File(args[i]));
            renameFile(fileList.get(i));
        }


public static void renameFile(File fileOriginal) throws IOException{
    File destination = new File(fileOriginal + "");
    try {


        File tempFile = File.createTempFile("buffer", ".tmp");
        System.out.println("File path: "+tempFile.getAbsolutePath());
        FileWriter fw = new FileWriter(tempFile);
        Reader fr = new FileReader(fileOriginal);
        BufferedReader br = new BufferedReader(fr);



        while (br.ready()) {
            fw.write(br.readLine().replace("#/A#" , "Á").  
                    replace("#/a#" , "á").  
                    replace("#:A#" , "Ä").  
                    replace("#:a#" , "ä").  
                    replace("#>C#" , "Č").  
                    replace("#>c#" , "č").  
                    replace("#>D#" , "Ď").  
                    replace("#d'#" , "ď").  
                    replace("#/I#" , "Í").  
                    replace("#/i#" , "í").  
                    replace("#L'#" , "Ľ").  
                    replace("#l'#" , "ľ").  
                    replace("#>N#" , "Ň").  
                    replace("#>n#" , "ň").  
                    replace("#/O#" , "Ó").  
                    replace("#/o#" , "ó").  
                    replace("#>r#" , "ř").  
                    replace("#/r#" , "ŕ").  
                    replace("#/R#" , "Ŕ").  
                    replace("#>S#" , "Š").  
                    replace("#>s#" , "š").  
                    replace("#/t#" , "ť").  
                    replace("#>T#" , "Ť").  
                    replace("#/U#" , "Ú").  //
                    replace("#/u#" , "ú").  
                    replace("#/Y#" , "Ý").  
                    replace("#/y#" , "ý").  
                    replace("#/Z#" , "Ź").  
                    replace("#/z#" , "ź").  
                    replace("#>Z#" , "Ž").  
                    replace("#>z#" , "ž").  
                    replace("#>E#" , "Ě").  
                    replace("#>e#" , "ě").  
                    replace("#>R#" , "Ř").  
                    replace("#oU#" , "Ů").  
                    replace("#ou#" , "ů")); 

        }

        fw.close();
        br.close();
        fr.close();

        //Rename original file in a .backup
        File originalFileRenamed = new File(fileOriginal + ".backup");
        if(fileOriginal.renameTo(originalFileRenamed))
            System.out.println("");
        else
            System.out.println("Original file already exist, cannot rename it, please delete it");


        //Rename the temp file I was working on.
        tempFile.renameTo(destination); 


    } catch (IOException e) {
        e.printStackTrace();
    }

很抱歉放了这么长的代码,但我无法找到问题的来源。

问题在于输出文件不会出现在Linux上,而是出现在Windows上。 程序自行执行,但不提供输出文件。

简而言之,我只是使用tempFile,buffer等在文件中写入。

由于

0 个答案:

没有答案