私はこの方法で読ん戻り、物事の読み取りファイルのオープンファイルのための3つの方法FileReaderのとBufferedReader
- を持っているが
を読んで、この私のコード:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication56;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author x
*/
public class RemoteFileObjectImpl extends java.rmi.server.UnicastRemoteObject implements RemoteFileObject
{
public RemoteFileObjectImpl() throws java.rmi.RemoteException {
super();
}
File f = null;
FileReader r = null;
BufferedReader bfr = null;
String output = "";
public void open(String fileName) {
//To read file passWord
f = new File(fileName);
}
public String readLine() {
try {
String temp = "";
String newLine = System.getProperty("line.separator");
r = new FileReader(f);
while ((temp = bfr.readLine()) != null) {
output += temp + newLine;
bfr.close();
}
}
catch (IOException ex) {
ex.printStackTrace();
}
return output;
}
public void close() {
try {
bfr.close();
} catch (IOException ex) {
}
}
public static void main(String[]args) throws RemoteException{
RemoteFileObjectImpl m = new RemoteFileObjectImpl();
m.open("C:\\Users\\x\\Documents\\txt.txt");
m.readLine();
m.close();
}
}
しかし、動作しません。
String result = m.readLine();
たり、保存したoutput
変数を使用します。
は「動作しない」十分ではありません。あなたが何を期待し、何を得たのかを説明してください。 – chr
これらのエラーは、Ranと私が理由を知らないときに表示されます。 アゲインjavaapplication56.RemoteFileObjectImpl.main(RemoteFileObjectImpl.java:73) – Seetah
のスレッドでの例外javaapplication56.RemoteFileObjectImpl.readLineで "メイン" のjava.lang.NullPointerException \t(RemoteFileObjectImpl.java:51) \t:あなたが何をしましたか代わりに何が起こったのだろうか? –