This document discusses input/output (I/O) in Java. It covers handling files and directories using the File class, understanding character-based and byte-based streams, and examples of character and binary file input/output. Character I/O uses Readers and Writers, while binary I/O uses DataStreams. A BufferedReader is required to read full lines of text from a file. Formatting output is handled using DecimalFormat since Java has no printf method. Streams can be chained together, such as a FileOutputStream chained to a DataOutputStream for binary file output.
Concept of file, Opening and closing of file, Modes, Input/ output function, Random access in file, Printing a file
A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. It is a ready made structure.
In C language, we use a structure pointer of file type to declare a file.....
Concept of file, Opening and closing of file, Modes, Input/ output function, Random access in file, Printing a file
A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. It is a ready made structure.
In C language, we use a structure pointer of file type to declare a file.....
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OWebStackAcademy
Java.io.File Class in Java. The File class is Java's representation of a file or directory path name. ... A file system may implement restrictions to certain operations on the actual file-system object, such as reading, writing, and executing. These restrictions are collectively known as access permissions.
The program uses console I/O to simply read its "standard input (stdin)"—which might be the keyboard, a file dump, or the output of some other program—and print to its "standard output (stdout)"—which might be the display or printer or another program or a file.
This presentation introduces basic concepts about the Java I/O framework based on input and output streams. These slides introduce the following concepts:
- Obtaining streams
- Reading / writing bytes
- Character encodings
- Text input / output
- Random access files
- Processing files
- URLs
- Serialization
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
In this core java training session, you will learn Java IO – Files, Streams and
Object Serialization. Topics covered in this session are:
• Java IO
• Files
• Streams
• Byte-based
• Character-based
• Object Serialization
For more information about this course visit on this link: https://www.mindsmapped.com/courses/software-development/learn-java-fundamentals-hands-on-training-on-core-java-concepts/
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™UiPathCommunity
In questo evento online gratuito, organizzato dalla Community Italiana di UiPath, potrai esplorare le nuove funzionalità di Autopilot, il tool che integra l'Intelligenza Artificiale nei processi di sviluppo e utilizzo delle Automazioni.
📕 Vedremo insieme alcuni esempi dell'utilizzo di Autopilot in diversi tool della Suite UiPath:
Autopilot per Studio Web
Autopilot per Studio
Autopilot per Apps
Clipboard AI
GenAI applicata alla Document Understanding
👨🏫👨💻 Speakers:
Stefano Negro, UiPath MVPx3, RPA Tech Lead @ BSP Consultant
Flavio Martinelli, UiPath MVP 2023, Technical Account Manager @UiPath
Andrei Tasca, RPA Solutions Team Lead @NTT Data
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfPeter Spielvogel
Building better applications for business users with SAP Fiori.
• What is SAP Fiori and why it matters to you
• How a better user experience drives measurable business benefits
• How to get started with SAP Fiori today
• How SAP Fiori elements accelerates application development
• How SAP Build Code includes SAP Fiori tools and other generative artificial intelligence capabilities
• How SAP Fiori paves the way for using AI in SAP apps
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
2. Input/Output2 www.corewebprogramming.com
Agenda
• Handling files and directories through the
File class
• Understanding which streams to use for
character-based or byte-based streams
• Character File input and output
• Formatting output
• Reading data from the console
• Binary File input and output
3. Input/Output3 www.corewebprogramming.com
File Class
• A File object can refer to either a file or a
directory
File file1 = new File("data.txt");
File file1 = new File("C:java");
– To obtain the path to the current working directory use
System.getProperty("user.dir");
– To obtain the file or path separator use
System.getProperty("file.separator");
System.getProperty("path.separator");
or
File.separator()
File.pathSeparator()
4. Input/Output4 www.corewebprogramming.com
Useful File Methods
• isFile/isDirectory
• canRead/canWrite
• length
– Length of the file in bytes (long) or 0 if nonexistant
• list
– If the File object is a directory, returns a String array of all the
files and directories contained in the directory; otherwise, null
• mkdir
– Creates a new subdirectory
• delete
– Deletes the directory and returns true if successful
• toURL
– Converts the file path to a URL object
5. Input/Output5 www.corewebprogramming.com
Directory Listing, Example
import java.io.*;
public class DirListing {
public static void main(String[] args) {
File dir = new File(System.getProperty("user.dir"));
if(dir.isDirectory()){
System.out.println("Directory of " + dir);
String[] listing = dir.list();
for(int i=0; i<listing.length; i++) {
System.out.println("t" + listing[i]);
}
}
}
}
7. Input/Output7 www.corewebprogramming.com
Input/Output
• The java.io package provides over 60
input/output classes (streams)
• Streams are combined (piped together) to
create a desired data source or sink
• Streams are either byte-oriented or
character-oriented
– Use DataStreams for byte-oriented I/O
– Use Readers and Writers for character-based I/O
• Character I/O uses an encoding scheme
• Note: An IOException may occur during
any I/O operation
8. Input/Output8 www.corewebprogramming.com
Character File Output
Desired … Methods Construction
Character File Ouput FileWriter File file = new File("filename");
write(int char) FileWriter fout = new FileWriter(file);
write(byte[] buffer) or
write(String str) FileWriter fout = new FileWriter("filename");
Buffered Character BufferedWriter File file = new File("filename");
File Output write(int char) FileWriter fout = new FileWriter(file);
write(char[] buffer) BufferedWriter bout = new BufferedWriter(fout);
write(String str) or
newLine() BufferedWriter bout = new BufferedWriter(
new FileWriter(
new File("filename")));
9. Input/Output9 www.corewebprogramming.com
Character File Output, cont.
Desired … Methods Construction
Character Output PrintWriter FileWriter fout = new FileWriter("filename");
write(int char) PrintWriter pout = new PrintWriter(fout);
write(char[] buffer) or
writer(String str) PrintWriter pout = new PrintWriter(
print( … ) new FileWriter("filename"));
println( … ) or
PrintWriter pout = new PrintWriter(
new BufferedWriter(
new FileWriter("filename")));
10. Input/Output10 www.corewebprogramming.com
FileWriter
• Constructors
– FileWriter(String filename)/FileWriter(File file)
• Creates a output stream using the default encoding
– FileWriter(String filename, boolean append)
• Creates a new output stream or appends to the existing output
stream (append = true)
• Useful Methods
– write(String str)/write(char[] buffer)
• Writes string or array of chars to the file
– write(int char)
• Writes a character (int) to the file
– flush
• Writes any buffered characters to the file
– close
• Closes the file stream after performing a flush
– getEncoding
• Returns the character encoding used by the file stream
11. Input/Output11 www.corewebprogramming.com
CharacterFileOutput, Example
import java.io.*;
public class CharacterFileOutput {
public static void main(String[] args) {
FileWriter out = null;
try {
out = new FileWriter("book.txt");
System.out.println("Encoding: " + out.getEncoding());
out.write("Core Web Programming");
out.close();
out = null;
} catch(IOException ioe) {
System.out.println("IO problem: " + ioe);
ioe.printStackTrace();
try {
if (out != null) {
out.close();
}
} catch(IOException ioe2) { }
}
}
}
12. Input/Output12 www.corewebprogramming.com
CharacterFileOutput, Result
> java CharacterFileOutput
Encoding: Cp1252
> type book.txt
Core Web Programming
• Note: Cp1252 is Windows Western Europe / Latin-1
– To change the system default encoding use
System.setProperty("file.encoding", "encoding");
– To specify the encoding when creating the output steam, use an
OutputStreamWriter
OutputStreamWriter out =
new OutputStreamWriter(
new FileOutputStream("book.txt", "8859_1"));
13. Input/Output13 www.corewebprogramming.com
Formatting Output
• Use DecimalFormat to control spacing
and formatting
– Java has no printf method
• Approach
1. Create a DecimalFormat object describing the
formatting
DecimalFormat formatter =
new DecimalFormat("#,###.##");
2. Then use the format method to convert values into
formatted strings
formatter.format(24.99);
14. Input/Output14 www.corewebprogramming.com
Formatting Characters
Symbol Meaning
0 Placeholder for a digit.
# Placeholder for a digit.
If the digit is leading or trailing zero, then don't display.
. Location of decimal point.
, Display comma at this location.
- Minus sign.
E Scientific notation.
Indicates the location to separate the mattissa from the exponent.
% Multipy the value by 100 and display as a percent.
15. Input/Output15 www.corewebprogramming.com
NumFormat, Example
import java.text.*;
public class NumFormat {
public static void main (String[] args) {
DecimalFormat science = new DecimalFormat("0.000E0");
DecimalFormat plain = new DecimalFormat("0.0000");
for(double d=100.0; d<140.0; d*=1.10) {
System.out.println("Scientific: " + science.format(d) +
" and Plain: " + plain.format(d));
}
}
}
17. Input/Output17 www.corewebprogramming.com
Character File Input
Desired … Methods Construction
Character File Input FileReader File file = new File("filename");
read() FileReader fin = new FileReader(file);
read(char[] buffer) or
FileReader fin = new FileReader("filename");
Buffered Character BufferedReader File file = new File("filename");
File Input read() FileReader fin = new FileReader(file);
read(char[] buffer) BufferedReader bin = new BufferedReader(fin);
readLine() or
BufferedReader bin = new BufferedReader(
new FileReader(
new File("filename")));
18. Input/Output18 www.corewebprogramming.com
FileReader
• Constructors
– FileReader(String filename)/FileReader(File file)
• Creates a input stream using the default encoding
• Useful Methods
– read/read(char[] buffer)
• Reads a single character or array of characters
• Returns –1 if the end of the steam is reached
– reset
• Moves to beginning of stream (file)
– skip
• Advances the number of characters
• Note: Wrap a BufferedReader around the FileReader to
read full lines of text using readLine
19. Input/Output19 www.corewebprogramming.com
CharacterFileInput, Example
import java.io.*;
public class CharacterFileInput {
public static void main(String[] args) {
File file = new File("book.txt");
FileReader in = null;
if(file.exists()) {
try {
in = new FileReader(file);
System.out.println("Encoding: " + in.getEncoding());
char[] buffer = new char[(int)file.length()];
in.read(buffer);
System.out.println(buffer);
in.close();
} catch(IOException ioe) {
System.out.println("IO problem: " + ioe);
ioe.printStackTrace();
...
}
}
}
}
20. Input/Output20 www.corewebprogramming.com
CharacterFileInput, Result
> java CharacterFileInput
Encoding: Cp1252
Core Web Programming
• Alternatively, could read file one line at a time:
BufferedReader in =
new BufferedReader(new FileReader(file));
String lineIn;
while ((lineIn = in.readLine()) != null) {
System.out.println(lineIn);
}
21. Input/Output21 www.corewebprogramming.com
Console Input
• To read input from the console, a stream
must be associated with the standard input,
System.in
import java.io.*;
public class IOInput{
public static void main(String[] args) {
BufferedReader keyboard;
String line;
try {
System.out.print("Enter value: ");
System.out.flush();
keyboard = new BufferedReader(
new InputStreamReader(System.in));
line = keyboard.readLine();
} catch(IOException e) {
System.out.println("Error reading input!"); }
}
}
}
22. Input/Output22 www.corewebprogramming.com
Binary File Input and Output
• Handle byte-based I/O using a
DataInputStream or DataOutputStream
– The readFully method blocks until all bytes are read or an EOF occurs
– Values are written in big-endian fashion regardless of computer platform
DataType DataInputStream DataOutputStream
byte readByte writeByte
short readShort writeShort
int readInt writeInt
long readLong writeLong
float readFloat writeFloat
double readDouble writeDouble
boolean readBoolean writeBoolean
char readChar writeChar
String readUTF writeUTF
byte[] readFully
23. Input/Output23 www.corewebprogramming.com
UCS Transformation Format –
UTF-8
• UTF encoding represents a 2-byte Unicode
character in 1-3 bytes
– Benefit of backward compatibility with existing ASCII
data (one-byte over two-byte Unicode)
– Disadvantage of different byte sizes for character
representation
UTF Encoding
Bit Pattern Representation
0xxxxxxx ASCII (0x0000 - 0x007F)
10xxxxxx Second or third byte
110xxxxx First byte in a 2-byte sequence (0x0080 - 0x07FF)
1110xxxx First byte in a 3-byte sequence (0x0800 - 0xFFFF)
24. Input/Output24 www.corewebprogramming.com
Binary File Output
Desired … Methods Construction
Binary File Output FileOutputStream File file = new File("filename");
bytes write(byte) FileOutputStream fout = new FileOutputStream(file);
write(byte[] buffer) or
FileOutputStream fout = new FileOutputStream("filename");
Binary File Output DataOutputStream File file = new File("filename");
byte writeByte(byte) FileOutputStream fout = new FileOutputStream(file);
short writeShort(short) DataOutputStream dout = new DataOutputStream(fout);
int writeInt(int)
long writeLong(long) or
float writeFloat(float)
double writeDouble(double) DataOutputStream dout = new DataOutputStream(
char writechar(char) new FileOutputStream(
boolean writeBoolean(boolean) new File("filename")));
writeUTF(string)
writeBytes(string)
writeChars(string)
25. Input/Output25 www.corewebprogramming.com
Binary File Output, cont.
Desired … Methods Construction
Buffered Binary BufferedOutputStream File file = new File("filename");
File Output flush() FileOutputStream fout = new FileOutputStream(file);
write(byte) BufferedOutputStream bout = new BufferedOutputStream(fout);
write(byte[] buffer, int off, int len) DataOutputStream dout = new DataOutputStream(bout);
or
DataOutputStream dout = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(
new File("filename"))));
26. Input/Output26 www.corewebprogramming.com
BinaryFileOutput, Example
import java.io.*;
public class BinaryFileOutput {
public static void main(String[] args) {
int[] primes = { 1, 2, 3, 5, 11, 17, 19, 23 };
DataOutputStream out = null;
try {
out = new DataOutputStream(
new FileOutputStream("primes.bin"));
for(int i=0; i<primes.length; i++) {
out.writeInt(primes[i]);
}
out.close();
} catch(IOException ioe) {
System.out.println("IO problem: " + ioe);
ioe.printStackTrace();
}
}
}
27. Input/Output27 www.corewebprogramming.com
Binary File Input
Desired … Methods Construction
Binary File Input FileInputStream File file = new File("filename");
bytes read() FileInputStream fin = new FileInputStream(file);
read(byte[] buffer) or
FileInputStream fin = new FileInputStream("filename");
Binary File Input DataInputStream File file = new File("filename");
byte readByte() FileInputStream fin = new FileInputStream(file);
short readShort() DataInputStream din = new DataInputStream(fin);
int readInt()
long readLong() or
float readFloat()
double readDouble() DataInputStream din = new DataInputStream(
char readchar() new FileInputStream(
boolean readBoolean() new File("filename")));
readUTF()
readFully(byte[] buffer)
28. Input/Output28 www.corewebprogramming.com
Binary File Input, cont.
Desired … Methods Construction
Bufferred Binary BufferedInputStream File file = new File("filename");
File Input read() FileInputStream fin = new FileInputStream(file);
read(byte[] buffer, int off, int len) BufferedInputStream bin = new BufferedInputStream(fin);
skip(long) DataInputStream din = new DataInputStream(bin);
or
DataInputStream din = new DataInputStream(
new BufferedInputStream(
new FileInputStream(
new File("filename"))));
29. Input/Output29 www.corewebprogramming.com
BinaryFileInput, Example
import java.io.*;
public class BinaryFileInput {
public static void main(String[] args) {
DataInputStream in = null;
File file = new File("primes.bin");
try {
in = new DataInputStream(
new FileInputStream(file));
int prime;
long size = file.length()/4; // 4 bytes per int
for(long i=0; i<size; i++) {
prime = in.readInt();
System.out.println(prime);
}
in.close();
} catch(IOException ioe) {
System.out.println("IO problem: " + ioe);
ioe.printStackTrace();
}
}
}
30. Input/Output30 www.corewebprogramming.com
Summary
• A File can refer to either a file or a
directory
• Use Readers and Writers for character-
based I/O
– A BufferedReader is required for readLine
– Java provides no printf; use DecimalFormat for formatted
output
• Use DataStreams for byte-based I/O
– Chain a FileOutputStream to a DataOutputStream for
binary file output
– Chain a FileInputStream to a DataInputStream for binary
file input