本文整理匯總了Java中java.io.FileReader.read方法的典型用法代碼示例。如果您正苦於以下問題:Java FileReader.read方法的具體用法?Java FileReader.read怎麽用?Java FileReader.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.FileReader
的用法示例。
在下文中一共展示了FileReader.read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadFile
import java.io.FileReader; //導入方法依賴的package包/類
/** Loads the file and performs conversion of line separators to LF.
* This method can be used in debuging of syntax scanner or somewhere else.
* @param fileName the name of the file to load
* @return array of loaded characters with '\n' as line separator
*/
public static char[] loadFile(String fileName) throws IOException {
File file = new File(fileName);
char chars[] = new char[(int)file.length()];
FileReader reader = new FileReader(file);
reader.read(chars);
reader.close();
int len = Analyzer.convertLSToLF(chars, chars.length);
if (len != chars.length) {
char copyChars[] = new char[len];
System.arraycopy(chars, 0, copyChars, 0, len);
chars = copyChars;
}
return chars;
}
示例2: test
import java.io.FileReader; //導入方法依賴的package包/類
public void test() throws Exception {
File testJComponentFile = new File(getDataDir() + "/testfiles/JComponent.java.txt");
FileReader r = new FileReader(testJComponentFile);
int fileLen = (int)testJComponentFile.length();
CharBuffer cb = CharBuffer.allocate(fileLen);
r.read(cb);
cb.rewind();
String text = cb.toString();
TokenHierarchy<?> hi = TokenHierarchy.create(text, JavaTokenId.language());
TokenSequence<?> ts = hi.tokenSequence();
System.err.println("Flyweight tokens: " + LexerTestUtilities.flyweightTokenCount(ts)
+ "\nTotal tokens: " + ts.tokenCount()
+ "\nFlyweight text length: " + LexerTestUtilities.flyweightTextLength(ts)
+ "\nTotal text length: " + fileLen
+ "\nDistribution: " + LexerTestUtilities.flyweightDistribution(ts)
);
assertEquals(LexerTestUtilities.flyweightTokenCount(ts), 13786);
assertEquals(LexerTestUtilities.flyweightTextLength(ts), 21710);
assertEquals(ts.tokenCount(), 21379);
}
示例3: readString
import java.io.FileReader; //導入方法依賴的package包/類
public static String readString(File file) {
StringBuffer str=new StringBuffer("");
try {
FileReader fr=new FileReader(file);
int ch;
while((ch = fr.read())!=-1 ) {
str.append((char)ch);
}
fr.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("File reader出錯");
}
return str.toString();
}
示例4: read
import java.io.FileReader; //導入方法依賴的package包/類
private static String read(File file)
{
StringBuilder text = new StringBuilder();
try
{
FileReader fileReader = new FileReader(file);
char buffer[] = new char[BUFFER_SIZE];
int n;
while ((n = fileReader.read(buffer)) != -1)
text.append(String.valueOf(buffer, 0, n));
fileReader.close();
}
catch (Exception e) {}
return text.toString();
}
示例5: main
import java.io.FileReader; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
String alphabetL = "abcdefghijklmnopqrstuvwxyz";
String alphabetH = alphabetL.toUpperCase();
FileReader f = new FileReader(args[0]);
int count = 0;
while (f.ready()) {
char s = (char) f.read();
if ((alphabetL.indexOf(s) > -1) || alphabetH.indexOf(s) > -1)
count++;
}
f.close();
System.out.println(count);
}
示例6: demoToCreateWriteAndReadFromFile
import java.io.FileReader; //導入方法依賴的package包/類
public void demoToCreateWriteAndReadFromFile() throws IOException {
File file = new File("project.txt");
file.createNewFile();
FileWriter fileWriter = new FileWriter(file);
fileWriter.write ("Hugo Boss \n Gucci \n Tommy Hilfiger \n Armani \n Salvatore \n Dolce & Gabbana \n");
fileWriter.flush();
fileWriter.close();
FileReader fileReader = new FileReader(file);
char[] charArrays = new char[100];
fileReader.read(charArrays);
for (char charArray : charArrays) {
System.out.println(charArray);
fileReader.close();
}
}
示例7: readFile
import java.io.FileReader; //導入方法依賴的package包/類
/**
*
**/
void readFile (IncludeEntry file, String filename) throws IOException
{
data.fileEntry = file;
data.filename = filename;
// <f49747.1>
//FileInputStream stream = new FileInputStream (data.filename);
//data.fileBytes = new byte [stream.available ()];
//stream.read (data.fileBytes);
//stream.close (); <ajb>
File idlFile = new File (data.filename);
int len = (int)idlFile.length ();
FileReader fileReader = new FileReader (idlFile);
// <d41679> data.fileBytes = new char [len];
final String EOL = System.getProperty ("line.separator");
data.fileBytes = new char [len + EOL.length ()];
fileReader.read (data.fileBytes, 0, len);
fileReader.close ();
// <d41679>
for (int i = 0; i < EOL.length (); i++)
data.fileBytes[len + i] = EOL.charAt (i);
readChar ();
}
示例8: areFilesIdentical
import java.io.FileReader; //導入方法依賴的package包/類
/** byte-by-byte comparison of two files. Returns true if they are identical */
//@TODO, if these is used to compare text files, we should ignore line endings!
public static boolean areFilesIdentical(File f1, File f2) throws Exception {
if (!f1.exists() || !f2.exists())
return false;
FileReader fr1 = new FileReader(f1);
FileReader fr2 = new FileReader(f2);
try {
long counter=0;
int x,y;
do {
counter++;
x=fr1.read();
y=fr2.read();
if(x==y && x==-1)
return true;
} while(x==y);
log.error("File compare failed at byte " + counter);
return false;
} finally {
fr1.close();
fr2.close();
}
}
示例9: main
import java.io.FileReader; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
// works with everyfile
String input = "input.txt";
FileReader reader = new FileReader(new File(input));
String output = "output.txt";
FileWriter writer = new FileWriter(new File(output));
int i;
System.out.println("File input from [" + input + "]\n");
while ((i = reader.read()) != -1) {
writer.write(i);
System.out.print((char)i);
}
reader.close();
writer.close();
}
示例10: authenticateWithPublicKey
import java.io.FileReader; //導入方法依賴的package包/類
/**
* A convenience wrapper function which reads in a private key (PEM format, either DSA or RSA)
* and then calls <code>authenticateWithPublicKey(String, char[], String)</code>.
* <p>
* NOTE PUTTY USERS: Event though your key file may start with "-----BEGIN..."
* it is not in the expected format. You have to convert it to the OpenSSH
* key format by using the "puttygen" tool (can be downloaded from the Putty
* website). Simply load your key and then use the "Conversions/Export OpenSSH key"
* functionality to get a proper PEM file.
*
* @param user A <code>String</code> holding the username.
* @param pemFile A <code>File</code> object pointing to a file containing a DSA or RSA
* private key of the user in OpenSSH key format (PEM, you can't miss the
* "-----BEGIN DSA PRIVATE KEY-----" or "-----BEGIN RSA PRIVATE KEY-----"
* tag).
* @param password If the PEM file is encrypted then you must specify the password.
* Otherwise, this argument will be ignored and can be set to <code>null</code>.
* @return whether the connection is now authenticated.
* @throws IOException
*/
public synchronized boolean authenticateWithPublicKey(String user, File pemFile, String password)
throws IOException {
if (pemFile == null)
throw new IllegalArgumentException("pemFile argument is null");
char[] buff = new char[256];
CharArrayWriter cw = new CharArrayWriter();
FileReader fr = new FileReader(pemFile);
while (true) {
int len = fr.read(buff);
if (len < 0)
break;
cw.write(buff, 0, len);
}
fr.close();
return authenticateWithPublicKey(user, cw.toCharArray(), password);
}
示例11: readFile
import java.io.FileReader; //導入方法依賴的package包/類
public static String readFile(File f) throws IOException {
FileReader r = new FileReader(f);
int fileLen = (int)f.length();
CharBuffer cb = CharBuffer.allocate(fileLen);
r.read(cb);
cb.rewind();
return cb.toString();
}
示例12: readJComponentFile
import java.io.FileReader; //導入方法依賴的package包/類
private String readJComponentFile() throws Exception {
File testJComponentFile = new File(getDataDir() + "/testfiles/JComponent.java.txt");
FileReader r = new FileReader(testJComponentFile);
try {
int fileLen = (int)testJComponentFile.length();
CharBuffer cb = CharBuffer.allocate(fileLen);
r.read(cb);
cb.rewind();
return cb.toString();
} finally {
r.close();
}
}
示例13: getScript
import java.io.FileReader; //導入方法依賴的package包/類
private String getScript(File file) throws IOException {
int size = (int) file.length();
char[] cs = new char[size + 64];
FileReader fileReader = new FileReader(file);
int n = fileReader.read(cs);
fileReader.close();
return new String(cs, 0, n);
}
示例14: fetchFileContents
import java.io.FileReader; //導入方法依賴的package包/類
private String fetchFileContents(File file)
throws IOException {
char[] buf = new char[20];
FileReader fr = new FileReader(file);
int cnt = fr.read(buf);
fr.close();
char[] result = Arrays.copyOf(buf, cnt);
return new String(result);
}
示例15: getUserMetadataXML
import java.io.FileReader; //導入方法依賴的package包/類
private String getUserMetadataXML(UserType userType) {
int ch = 0;
StringBuffer buf = new StringBuffer();
try {
FileReader reader = new FileReader(userType.getSrcFile());
while ((ch = reader.read()) != -1) {
buf.append((char) ch);
}
reader.close();
return buf.toString();
} catch (Exception e) {
throw new RalasafeException(e);
}
}