Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 532ff0c

Browse filesBrowse files
committed
优化“用java怎么创建一个文件并向该文件写文本内容”
1 parent d1deb8e commit 532ff0c
Copy full SHA for 532ff0c

File tree

Expand file treeCollapse file tree

2 files changed

+4
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+4
-3
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ stackoverflow-Java-top-qa
5151
* [反射是什么及其用途](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/What-is-reflection-and-why-is-it-useful.md)
5252
* [为什么不能用string类型进行switch判断](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Why-can't-I-switch-on-a-String.md)
5353
* [比较java枚举成员使用equal还是==](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/comparing-java-enum-members-or-equals.md)
54+
* [用java怎么创建一个文件并向该文件写文本内容](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-create-a-file-and-write-to-a-file-in-java.md)
5455

5556
> 编程技巧
5657
@@ -137,7 +138,6 @@ stackoverflow-Java-top-qa
137138
- [Why does Math.round(0.49999999999999994) return 1](http://stackoverflow.com/questions/9902968/why-does-math-round0-49999999999999994-return-1)
138139
- [Eclipse: Set maximum line length for auto formatting?](http://stackoverflow.com/questions/3697287/eclipse-set-maximum-line-length-for-auto-formatting)
139140
- [What is the difference between a soft reference and a weak reference in Java?](http://stackoverflow.com/questions/299659/what-is-the-difference-between-a-soft-reference-and-a-weak-reference-in-java)
140-
- [How to create a file and write to a file in Java?](http://stackoverflow.com/questions/2885173/how-to-create-a-file-and-write-to-a-file-in-java)
141141
- [What is the equivalent of the C++ Pair<L,R> in Java?](http://stackoverflow.com/questions/156275/what-is-the-equivalent-of-the-c-pairl-r-in-java)
142142
- [What is the difference between JSF, Servlet and JSP?](http://stackoverflow.com/questions/2095397/what-is-the-difference-between-jsf-servlet-and-jsp)
143143
- [How do I “decompile” Java class files?](http://stackoverflow.com/questions/272535/how-do-i-decompile-java-class-files)

‎contents/how-to-create-a-file-and-write-to-a-file-in-java.md

Copy file name to clipboardExpand all lines: contents/how-to-create-a-file-and-write-to-a-file-in-java.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 用java怎么样创建一个文件并向该文件写文本内容
1+
## 用java怎么创建一个文件并向该文件写文本内容
22

33
### 问:在java里最简单的创建文件写文件的方法是什么
44

@@ -10,7 +10,7 @@ writer.println("The first line");
1010
writer.println("The second line");
1111
writer.close();
1212
````
13-
创建一个位二进制文件(同样会覆盖这文件)
13+
创建一个二进制文件(同样会覆盖这文件)
1414
````java
1515
byte data[] = ...
1616
FileOutputStream out = new FileOutputStream("the-file-name");
@@ -45,6 +45,7 @@ try (Writer writer = new BufferedWriter(new OutputStreamWriter(
4545
还有一些实用的方法如下:
4646
* [`FileUtils.writeStringtoFile(..)`](https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#writeStringToFile%28java.io.File,%20java.lang.String,%20java.nio.charset.Charset%29) 来自于 commons-io 包
4747
* [`Files.write(..)`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/io/Files.html#write%28java.lang.CharSequence,%20java.io.File,%20java.nio.charset.Charset%29) 来自于 guava
48+
4849
Note also that you can use a FileWriter, but it uses the default encoding,
4950
which is often a bad idea - it's best to specify the encoding explicitly.
5051
还要注意可以使用 `FileWriter`,但是它使用的是默认编码,这不是很好的方法,最好是明确指定编码

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.