读取文本文件:错误 - FileWriter类型的变量

时间:2017-07-27 17:03:48

标签: java compiler-errors

import java.io.*;
import java.util.*;

class Permutation { 
    static void combinationUtil(int arr[], int n, int r, FileWriter out, int index,int data[], int i)
    {
       if (index == r)
        {
            for (int j=0; j<r; j++)
              out.print(data[j]+"  ");
              out.println(" ");

        return;
        }


        if (i >= n)
        return;


        data[index] = arr[i];
        combinationUtil(arr, n, r, out, index+1, data, i+1);
        combinationUtil(arr, n, r, out, index, data, i+1);      
    }


    static void printCombination(int arr[], int n, int r, FileWriter out)
    {

        int data[]=new int[r];
        combinationUtil(arr, n, r,out, 0, data, 0);
    }


    public static void main (String[] args) {
      File file = new File("output.txt");
      file.createNewFile();
      FileWriter out = new FileWriter(file); 
      int arr[] = {1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};
      int r = 6;
      int n = arr.length;
      printCombination(arr, n, r, out); 
      out.flush();
      out.close();   
    }//end main
}//end calss

错误

  

C:\ Users \ Student \ Documents \ Permutation.java:21:error:找不到符号                 out.print(data [j] +&#34;&#34;);                    ^     符号:方法print(String)     location:FileWriter类型的变量   1错误

流程已完成。 在解决此错误时遇到问题有帮助。我尝试使用单独的函数传递它,但它不起作用。

2 个答案:

答案 0 :(得分:1)

outSystem的静态成员,应该这样调用 - System.out.print(data[j]+" ")

答案 1 :(得分:-1)

out.print无法上班。你想要

System.out.print(data[j] + " ")

如果我没记错的话,你还必须导入系统。