本文整理了Java中com.google.common.io.Files.toString()
方法的一些代码示例,展示了Files.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.toString()
方法的具体详情如下:
包路径:com.google.common.io.Files
类名称:Files
方法名:toString
[英]Reads all characters from a file into a String, using the given character set.
[中]使用给定的字符集将文件中的所有字符读入字符串。
代码示例来源:origin: springside/springside4
/**
* 读取文件到String.
*/
public static String toString(final File file) throws IOException {
return com.google.common.io.Files.toString(file, Charsets.UTF_8);
}
代码示例来源:origin: SonarSource/sonarqube
@Override
protected String readString(URI uri, Charset charset) {
try {
return Files.toString(new File(uri), charset);
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: prestodb/presto
public BenchmarkQuery(File file)
throws IOException
{
requireNonNull(file, "file is null");
name = Files.getNameWithoutExtension(file.getName());
// file can have 2 sections separated by a line of equals signs
String text = Files.toString(file, StandardCharsets.UTF_8);
List<String> sections = SECTION_SPLITTER.splitToList(text);
if (sections.size() == 2) {
this.tags = ImmutableMap.copyOf(TAGS_SPLITTER.split(sections.get(0)));
this.sql = sections.get(1);
}
else {
// no tags
this.tags = ImmutableMap.of();
this.sql = sections.get(0);
}
}
代码示例来源:origin: google/guava
public void testToString() throws IOException {
File asciiFile = getTestFile("ascii.txt");
File i18nFile = getTestFile("i18n.txt");
assertEquals(ASCII, Files.toString(asciiFile, Charsets.US_ASCII));
assertEquals(I18N, Files.toString(i18nFile, Charsets.UTF_8));
assertThat(Files.toString(i18nFile, Charsets.US_ASCII)).isNotEqualTo(I18N);
}
代码示例来源:origin: google/guava
public void testWriteString() throws IOException {
File temp = createTempFile();
Files.write(I18N, temp, Charsets.UTF_16LE);
assertEquals(I18N, Files.toString(temp, Charsets.UTF_16LE));
}
代码示例来源:origin: google/guava
public void testCopyIdenticalFiles() throws IOException {
File temp1 = createTempFile();
Files.write(ASCII, temp1, Charsets.UTF_8);
File temp2 = createTempFile();
Files.write(ASCII, temp2, Charsets.UTF_8);
Files.copy(temp1, temp2);
assertEquals(ASCII, Files.toString(temp1, Charsets.UTF_8));
}
代码示例来源:origin: google/guava
public void testCopySameFile() throws IOException {
File temp = createTempFile();
Files.write(ASCII, temp, Charsets.UTF_8);
try {
Files.copy(temp, temp);
fail("Expected an IAE to be thrown but wasn't");
} catch (IllegalArgumentException expected) {
}
assertEquals(ASCII, Files.toString(temp, Charsets.UTF_8));
}
代码示例来源:origin: google/guava
public void testAppendString() throws IOException {
File temp = createTempFile();
Files.append(I18N, temp, Charsets.UTF_16LE);
assertEquals(I18N, Files.toString(temp, Charsets.UTF_16LE));
Files.append(I18N, temp, Charsets.UTF_16LE);
assertEquals(I18N + I18N, Files.toString(temp, Charsets.UTF_16LE));
Files.append(I18N, temp, Charsets.UTF_16LE);
assertEquals(I18N + I18N + I18N, Files.toString(temp, Charsets.UTF_16LE));
}
代码示例来源:origin: google/guava
public void testCopyFile() throws IOException {
File i18nFile = getTestFile("i18n.txt");
File temp = createTempFile();
Files.copy(i18nFile, temp);
assertEquals(I18N, Files.toString(temp, Charsets.UTF_8));
}
代码示例来源:origin: google/guava
public void testCopyEqualFiles() throws IOException {
File temp1 = createTempFile();
File temp2 = file(temp1.getPath());
assertEquals(temp1, temp2);
Files.write(ASCII, temp1, Charsets.UTF_8);
try {
Files.copy(temp1, temp2);
fail("Expected an IAE to be thrown but wasn't");
} catch (IllegalArgumentException expected) {
}
assertEquals(ASCII, Files.toString(temp1, Charsets.UTF_8));
}
代码示例来源:origin: airbnb/DeepLinkDispatch
@Test public void testWrite() throws IOException {
when(options.get(Documentor.DOC_OUTPUT_PROPERTY_NAME)).thenReturn(FILE_PATH);
Documentor documentor = new Documentor(processingEnv);
documentor.write(getElements());
String actual = Files.toString(new File(FILE_PATH), Charsets.UTF_8);
String expected = "airbnb://example.com/{foo}/bar\\n|#|\\nSample doc\\n|#|\\nDocClass\\"
+ "n|##|\\nairbnb://example.com/{foo}/bar\\n|#|\\n\\n|#|\\nDocClass#DocMethod\\n|##|\\n";
assertEquals(expected, actual);
}
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws IOException {
assertThat(helper.postContent(remoteUrl("/proxy"), "proxy"), is("proxy"));
assertThat(Files.toString(tempFile, Charset.defaultCharset()), containsString("proxy"));
}
});
代码示例来源:origin: dreamhead/moco
@Test
public void should_fire_event_with_post_url_template() throws IOException {
runWithConfiguration("event.json");
File file = folder.newFile();
System.setOut(new PrintStream(new FileOutputStream(file)));
assertThat(helper.get(remoteUrl("/post-event-with-template-url")), is("post_foo"));
idle(IDLE, TimeUnit.MILLISECONDS);
assertThat(Files.toString(file, Charset.defaultCharset()), containsString("0XCAFEBABE"));
}
代码示例来源:origin: dreamhead/moco
@Test
public void should_fire_get_event() throws IOException {
runWithConfiguration("event.json");
File file = folder.newFile();
System.setOut(new PrintStream(new FileOutputStream(file)));
assertThat(helper.get(remoteUrl("/get_event")), is("get_foo"));
idle(IDLE, TimeUnit.MILLISECONDS);
assertThat(Files.toString(file, Charset.defaultCharset()), containsString("0XCAFEBABE"));
}
代码示例来源:origin: dreamhead/moco
@Test
public void should_fire_get_event_with_template() throws IOException {
runWithConfiguration("event.json");
File file = folder.newFile();
System.setOut(new PrintStream(new FileOutputStream(file)));
assertThat(helper.get(remoteUrl("/get_event_template")), is("get_foo"));
idle(IDLE, TimeUnit.MILLISECONDS);
assertThat(Files.toString(file, Charset.defaultCharset()), containsString("0XCAFEBABE"));
}
代码示例来源:origin: dreamhead/moco
@Test
public void should_fire_event_with_unit() throws IOException {
runWithConfiguration("event.json");
File file = folder.newFile();
System.setOut(new PrintStream(new FileOutputStream(file)));
assertThat(helper.get(remoteUrl("/event-with-unit")), is("post_foo"));
idle(IDLE, TimeUnit.MILLISECONDS);
assertThat(Files.toString(file, Charset.defaultCharset()), containsString("0XCAFEBABE"));
}
代码示例来源:origin: dreamhead/moco
@Test
public void should_fire_event_with_post_json() throws IOException {
runWithConfiguration("event.json");
File file = folder.newFile();
System.setOut(new PrintStream(new FileOutputStream(file)));
assertThat(helper.get(remoteUrl("/event-with-json-post")), is("post_json_foo"));
idle(IDLE, TimeUnit.MILLISECONDS);
assertThat(Files.toString(file, Charset.defaultCharset()), containsString("0XMOCOJSON"));
}
}
代码示例来源:origin: querydsl/querydsl
@Test
public void export_with_keywords() throws IOException {
exporter.setKeywords(Keywords.JPA);
exporter.setTargetFolder(folder.getRoot());
exporter.export(getClass().getPackage());
String str = Files.toString(new File(folder.getRoot(), "com/querydsl/codegen/QGroup.java"), Charsets.UTF_8);
assertTrue(str.contains("QGroup group = new QGroup(\"group1\");"));
}
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws IOException {
assertThat(helper.get(remoteUrl("/proxy")), is("get_proxy"));
assertThat(helper.postContent(remoteUrl("/proxy"), "proxy"), is("post_proxy"));
String failoverContent = Files.toString(tempFile, Charset.defaultCharset());
assertThat(failoverContent, containsString("get_proxy"));
assertThat(failoverContent, containsString("post_proxy"));
}
});
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws IOException {
assertThat(helper.postContent(remoteUrl("/proxy"), "proxy"), is("0XCAFEBABE"));
assertThat(helper.postContent(remoteUrl("/proxy"), "proxy"), is("0XCAFEBABE"));
assertThat(Files.toString(tempFile, Charset.defaultCharset()), countString("/proxy", 1));
}
});
内容来源于网络,如有侵权,请联系作者删除!