Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
javab_20230928
Commits
170a4828
Commit
170a4828
authored
Nov 09, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Odczyt za pomocą URL
parent
4b0d32ea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
Klient01_URL.java
PC36-RestKlient/src/main/java/rest_klient/Klient01_URL.java
+26
-0
No files found.
PC36-RestKlient/src/main/java/rest_klient/Klient01_URL.java
0 → 100644
View file @
170a4828
package
rest_klient
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
public
class
Klient01_URL
{
public
static
void
main
(
String
[]
args
)
{
// Najprostszy sposób w Javie, aby pobrac dane z adresu URL, to użyć klasy URL.
try
{
URL
url
=
new
URL
(
"http://localhost:8080/PC35-RestSerwer/products.json"
);
System
.
out
.
println
(
"Odczytuję dane..."
);
try
(
InputStream
input
=
url
.
openStream
())
{
// teraz z inputa możemy czytać ciąg bajtów
// ja przerzucę bajty czytane z sieci bezpośrednio do System.out
// (w przypadku obcego serwisu może być to niebezpieczne)
input
.
transferTo
(
System
.
out
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment