當前位置: 首頁>>代碼示例>>Java>>正文


Java FileReader.read方法代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:Analyzer.java

示例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);
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:JavaFlyTokensTest.java

示例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();

}
 
開發者ID:xfangfang,項目名稱:PhotoScript,代碼行數:18,代碼來源:IOUtils.java

示例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();
}
 
開發者ID:billthefarmer,項目名稱:diary,代碼行數:18,代碼來源:Editor.java

示例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);

}
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:18,代碼來源:Solution.java

示例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();
    }
}
 
開發者ID:cyber-coders-j2017a,項目名稱:modern.core.java.repo,代碼行數:19,代碼來源:Geography.java

示例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 ();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:Scanner.java

示例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();
    }
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:26,代碼來源:UnitTestUtil.java

示例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();
}
 
開發者ID:BedrockDev,項目名稱:Sunrin2017,代碼行數:21,代碼來源:CharacterStreamTest02.java

示例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);
}
 
開發者ID:fast-data-transfer,項目名稱:fdt,代碼行數:43,代碼來源:Connection.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:CslTestBase.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:JavaLexerPerformanceTest.java

示例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);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:9,代碼來源:DDTestRunner.java

示例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);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:10,代碼來源:TestHardLink.java

示例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);
	}
}
 
開發者ID:yswang0927,項目名稱:ralasafe,代碼行數:15,代碼來源:UserTypeManagerImpl.java


注:本文中的java.io.FileReader.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。