0
其他类的方法,我有两个类:如何存取权限在java中
- 类actUI
公共类ActUI扩展javax.swing.JFrame中{
//有这里的其他类
private static void writeToFile(java.util.List list, String path) { BufferedWriter out = null; try { File file = new File(path); out = new BufferedWriter(new FileWriter(file, true)); for (Object s : list) { out.write((String) s); out.newLine(); } out.close(); } catch (IOException e) { } UniqueLineReader ULR = new UniqueLineReader(); ULR.setFileName(path); } //there are the other classes here }
- 类UniqueLineReader:
公共类UniqueLineReader延伸的BufferedReader {
Set<String> lines = new HashSet<String>(); private Reader arg0; public UniqueLineReader(Reader arg0) { super(arg0); } @Override public String readLine() throws IOException { String uniqueLine; while (lines.add(uniqueLine = super.readLine()) == false); //read until encountering a unique line return uniqueLine; } public void setFileName(String filePath){ try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("test.txt"); UniqueLineReader br = new UniqueLineReader(new InputStreamReader(fstream)); String strLine; // Read File Line By Line PrintWriter outFile2 = new PrintWriter(new File("result.txt")); String result = ""; List data = new ArrayList(); while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println(strLine); data.add(strLine); } writeToFile(data, "result.txt"); // Close the input stream //in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } }
}
我想从将writeToFile方法存取权限UniqueLineReader在actUI中,但我的代码不工作,我怎么能没有错误呢,请帮助我。
你什么样的错误? – Thilo 2014-09-22 04:28:31
只需一分钟,你有两个方法称为'writeToFile()'在两个不同的类?不好的设计伙伴...重构你的代码! – alfasin 2014-09-22 04:34:55