当前位置: 首页>>代码示例>>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;未经允许,请勿转载。