- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to write int array to a file
Here’s our file −
FileWriter writer = new FileWriter("E:/demo.txt");
Now, consider an Integer array −
Integer arr[] = { 10, 20, 30, 40, 50 };
Write the above array to the file “demo.txt” −
int len = arr.length; for (int i = 0; i < len; i++) { writer.write(arr[i] + "\t" + ""); }
The following is an example. Here, our file is “E:/input.txt” −
Example
import java.io.FileWriter; public class Demo { public static void main(String[] argv) throws Exception { FileWriter writer = new FileWriter("E:/input.txt"); Integer arr[] = { 10, 20, 30, 40, 50 }; int len = arr.length; for (int i = 0; i < len; i++) { writer.write(arr[i] + "\t"+ ""); } writer.close(); } }
The output is as follows i.e. the text in the file is −
Output
1020304050
Advertisements